d3m.utils¶
-
class
d3m.utils.AbstractMetaclass(name, bases, namespace, **kwargs)[source]¶ Bases:
abc.ABCMeta,d3m.utils.MetaclassA metaclass which makes sure docstrings are inherited. For use with abstract classes.
-
class
d3m.utils.CallbackHandler(callback)[source]¶ Bases:
logging.HandlerCalls a
callbackwith logging records as they are without any conversion except for:formatting the logging message and adding it to the record object
assuring
asctimeis setconverts exception
exc_infointo exception’s namemaking sure
argsare JSON-compatible or removing itmaking sure there are no null values
-
class
d3m.utils.Enum(value)[source]¶ Bases:
enum.EnumAn extension of Enum base class where:
Instances are equal to their string names, too.
It registers itself with “yaml” module to serialize itself as a string.
Allows dynamic registration of additional values using
register_value.
-
class
d3m.utils.FileType(mode='r', bufsize=- 1, encoding=None, errors=None)[source]¶ Bases:
argparse.FileType
-
class
d3m.utils.GenericMetaclass(name, bases, namespace, tvars=None, args=None, origin=None, extra=None, orig_bases=None)[source]¶ Bases:
GenericMeta,d3m.utils.MetaclassA metaclass which makes sure docstrings are inherited. For use with generic classes (which are also abstract).
-
class
d3m.utils.JsonEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]¶ Bases:
json.encoder.JSONEncoderJSON encoder with extensions, among them the main ones are:
Frozen dict is encoded as a dict.
Python types are encoded into strings describing them.
Python enumerations are encoded into their string names.
Sets are encoded into lists.
Encodes ndarray and DataFrame as nested lists.
Encodes datetime into ISO format with UTC timezone.
Everything else which cannot be encoded is converted to a string.
You probably want to use to_json_structure and not this class, because to_json_structure also encodes
NaN`, ``Infinity, and-Infinityas strings.It does not necessary make a JSON which can then be parsed back to reconstruct original value.
-
class
d3m.utils.Metaclass(class_name, class_bases, class_dict)[source]¶ Bases:
custom_inherit._metaclass_base.DocInheritorBaseA metaclass which makes sure docstrings are inherited.
It knows how to merge numpy-style docstrings and merge parent sections with child sections. For example, then it is not necessary to repeat documentation for parameters if they have not changed.
-
class
d3m.utils.PMap(size, buckets)[source]¶ Bases:
pyrsistent._pmap.PMapExtends pyrsistent.PMap to (by default) iterate over its items in sorted order.
-
class
d3m.utils.RefResolverNoRemote(base_uri, referrer, store=(), cache_remote=True, handlers=(), urljoin_cache=None, remote_cache=None)[source]¶ Bases:
jsonschema.validators.RefResolver
-
class
d3m.utils.global_randomness_warning(enable=True)[source]¶ Bases:
contextlib.AbstractContextManagerA Python context manager which issues a warning if global sources of randomness are used. Currently it checks Python built-in global random source, NumPy global random source, and NumPy
default_rngbeing used without a seed.
-
class
d3m.utils.redirect_to_logging(logger=None, stdout_level='INFO', stderr_level='ERROR', pass_through=True)[source]¶ Bases:
contextlib.AbstractContextManagerA Python context manager which redirects all writes to stdout and stderr to Python logging.
Primitives should use logging to log messages, but maybe they are not doing that or there are other libraries they are using which are not doing that. One can then use this context manager to assure that (at least all Python) writes to stdout and stderr by primitives are redirected to logging:
with redirect_to_logging(logger=PrimitiveClass.logger): primitive = PrimitiveClass(...) primitive.set_training_data(...) primitive.fit(...) primitive.produce(...)
-
d3m.utils.check_immutable(obj)[source]¶ Checks that
objis immutable. Raises an exception if this is not true.- Parameters
obj (
Any) – Object to check.- Return type
None
-
d3m.utils.compute_digest(obj, extra_data=None)[source]¶ Input should be a JSON compatible structure.
- Return type
-
d3m.utils.create_enum_from_json_schema_enum(class_name, obj, json_paths, *, module=None, qualname=None, base_class=None)[source]¶ - Return type
-
d3m.utils.current_git_commit(path, search_parent_directories=True)[source]¶ Returns a git commit hash of the repo at
pathor above ifsearch_parent_directoriesisTrue.When used to get a commit hash of a Python package, for this to work, the package has to be installed in “editable” mode (
pip install -e).
-
d3m.utils.ensure_uri_ends_with_slash(uri)[source]¶ Add slash (/) to the URI if it doesn’t end with one.
- Return type
-
d3m.utils.get_datasets_and_problems(datasets_dir, handle_score_split=True, *, ignore_duplicate=False)[source]¶
-
d3m.utils.get_type_arguments(cls, *, unique_names=False)[source]¶ Returns a mapping between type arguments and their types of a given class
cls.
-
d3m.utils.has_duplicates(data)[source]¶ Returns
Trueifdatahas duplicate elements.It works both with hashable and not-hashable elements.
- Return type
-
d3m.utils.json_structure_equals(obj1, obj2, ignore_keys=None)[source]¶ - Parameters
- Returns
A boolean indicating whether
obj1andobj2are equal.- Return type
-
d3m.utils.load_schema_validators(schemas, load_validators)[source]¶ - Return type
List[Draft7Validator]
-
d3m.utils.log_once(logger, level, msg, *args, ignore_modules=None, **kwargs)[source]¶ - Return type
None
-
d3m.utils.make_immutable_copy(obj)[source]¶ Converts a given
objinto an immutable copy of it, if possible.
-
d3m.utils.matches_structural_type(source_structural_type, target_structural_type)[source]¶ - Return type
-
d3m.utils.to_json_structure(obj)[source]¶ In addition to what JsonEncoder encodes, this function also encodes as strings float
NaN,Infinity, and-Infinity.It does not necessary make a JSON structure which can then be parsed back to reconstruct original value. For that use
to_reversible_json_structure.- Return type