-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make release-tag: Merge branch 'master' into stable
- Loading branch information
Showing
57 changed files
with
4,011 additions
and
2,445 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{% set version = '0.10.1' %} | ||
{% set version = '0.11.0.dev1' %} | ||
|
||
package: | ||
name: "{{ name|lower }}" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,13 +4,18 @@ | |
|
||
__author__ = 'MIT Data To AI Lab' | ||
__email__ = '[email protected]' | ||
__version__ = '0.10.1' | ||
__version__ = '0.11.0.dev1' | ||
|
||
import sys | ||
import warnings as python_warnings | ||
from operator import attrgetter | ||
from types import ModuleType | ||
|
||
import pandas as pd | ||
from pkg_resources import iter_entry_points | ||
|
||
from sdmetrics import ( | ||
column_pairs, demos, goal, multi_table, single_column, single_table, timeseries) | ||
from sdmetrics._addons import _find_addons | ||
from sdmetrics.demos import load_demo | ||
|
||
__all__ = [ | ||
|
@@ -24,8 +29,6 @@ | |
'timeseries', | ||
] | ||
|
||
_find_addons(group='sdmetrics_modules', parent_globals=globals()) | ||
|
||
|
||
def compute_metrics(metrics, real_data, synthetic_data, metadata=None, **kwargs): | ||
"""Compute a collection of metrics on the given data. | ||
|
@@ -75,3 +78,82 @@ def compute_metrics(metrics, real_data, synthetic_data, metadata=None, **kwargs) | |
}) | ||
|
||
return pd.DataFrame(scores) | ||
|
||
|
||
def _get_addon_target(addon_path_name): | ||
"""Find the target object for the add-on. | ||
Args: | ||
addon_path_name (str): | ||
The add-on's name. The add-on's name should be the full path of valid Python | ||
identifiers (i.e. importable.module:object.attr). | ||
Returns: | ||
tuple: | ||
* object: | ||
The base module or object the add-on should be added to. | ||
* str: | ||
The name the add-on should be added to under the module or object. | ||
""" | ||
module_path, _, object_path = addon_path_name.partition(':') | ||
module_path = module_path.split('.') | ||
|
||
if module_path[0] != __name__: | ||
msg = f"expected base module to be '{__name__}', found '{module_path[0]}'" | ||
raise AttributeError(msg) | ||
|
||
target_base = sys.modules[__name__] | ||
for submodule in module_path[1:-1]: | ||
target_base = getattr(target_base, submodule) | ||
|
||
addon_name = module_path[-1] | ||
if object_path: | ||
if len(module_path) > 1 and not hasattr(target_base, module_path[-1]): | ||
msg = f"cannot add '{object_path}' to unknown submodule '{'.'.join(module_path)}'" | ||
raise AttributeError(msg) | ||
|
||
if len(module_path) > 1: | ||
target_base = getattr(target_base, module_path[-1]) | ||
|
||
split_object = object_path.split('.') | ||
addon_name = split_object[-1] | ||
|
||
if len(split_object) > 1: | ||
target_base = attrgetter('.'.join(split_object[:-1]))(target_base) | ||
|
||
return target_base, addon_name | ||
|
||
|
||
def _find_addons(): | ||
"""Find and load all SDMetrics add-ons. | ||
If the add-on is a module, we add it both to the target module and to | ||
``system.modules`` so that they can be imported from the top of a file as follows: | ||
from top_module.addon_module import x | ||
""" | ||
group = 'sdmetrics_modules' | ||
for entry_point in iter_entry_points(group=group): | ||
try: | ||
addon = entry_point.load() | ||
except Exception: # pylint: disable=broad-exception-caught | ||
msg = f'Failed to load "{entry_point.name}" from "{entry_point.module_name}".' | ||
python_warnings.warn(msg) | ||
continue | ||
|
||
try: | ||
addon_target, addon_name = _get_addon_target(entry_point.name) | ||
except AttributeError as error: | ||
msg = f"Failed to set '{entry_point.name}': {error}." | ||
python_warnings.warn(msg) | ||
continue | ||
|
||
if isinstance(addon, ModuleType): | ||
addon_module_name = f'{addon_target.__name__}.{addon_name}' | ||
if addon_module_name not in sys.modules: | ||
sys.modules[addon_module_name] = addon | ||
|
||
setattr(addon_target, addon_name, addon) | ||
|
||
|
||
_find_addons() |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.