def _enter(path, key, value): """If `value` is in `keras.callbacks`, enter as a dict, iterating over non-magic attributes. Else, `default_enter`""" if isinstance(value, base_keras_callback): return dict(), [(_, getattr(value, _)) for _ in dir(value) if not _.startswith("__")] return default_enter(path, key, value)
def _enter(path, key, value): """If any in `iter_attrs` is True, enter `value` as a dict, iterating over non-magic attributes. Else, `default_enter`""" if any([_(path, key, value) for _ in iter_attrs]): included_attrs = [_ for _ in dir(value) if not _.startswith("__")] return dict(), [(_, getattr(value, _)) for _ in included_attrs] return default_enter(path, key, value)
def layer_enter(path, key, value): """If Keras `Initializer`, enter as dict, iterating over non-magic attributes""" if isinstance(value, BaseKerasInitializer): return ( dict(), [(_, getattr(value, _)) for _ in dir(value) if _ != "__hh_previous_frame" and not _.endswith("__")], ) return default_enter(path, key, value)
def enter(path, key, value): """Produce iterable of attributes to remap for instances of :class:`metrics.Metric`""" if isinstance(value, Metric): metric_attrs = ["name", "metric_function", "direction"] return ({}, [(_, getattr(value, _)) for _ in metric_attrs]) if isinstance(value, EngineerStep): return ({}, list(value.get_key_data().items())) if isinstance(value, FeatureEngineer): return ({}, list(value.get_key_data().items())) return default_enter(path, key, value)
def _enter(path, key, value): """If any in `iter_attrs` is True, enter `value` as a dict, iterating over non-magic attributes. Else, `default_enter`""" if any([_(path, key, value) for _ in iter_attrs]): included_attrs = [_ for _ in dir(value) if not _.endswith("__")] # Skips "dunder" methods, but keeps "__hh" attributes return dict(), [(_, getattr(value, _)) for _ in included_attrs] # TODO: Find better way to avoid entering "__hh_previous_frame" to avoid Traceback added by `tracers.LocationTracer` if isinstance(value, Traceback): return dict(), [] # TODO: Find better way to avoid entering "__hh_previous_frame" to avoid Traceback added by `tracers.LocationTracer` return default_enter(path, key, value)
def _enter(path, key, value): """If any in `iter_attrs` is True, enter `value` as a dict, iterating over non-magic attributes. Else, `default_enter`""" if any([_(path, key, value) for _ in iter_attrs]): included_attrs = [_ for _ in dir(value) if not _.endswith("__")] # type: List[str] # Skips "dunder" methods, but keeps "__hh" attributes included_attrs = sorted(included_attrs, reverse=True) # Reverse to put public attributes before private - Without reversal, `remap` ignores # `FeatureEngineer.steps` property because the identical `_steps` was already visited return dict(), [(_, getattr(value, _)) for _ in included_attrs] # TODO: Find better way to avoid entering "__hh_previous_frame" to avoid Traceback added by `tracers.LocationTracer` if isinstance(value, Traceback): return dict(), [] # TODO: Find better way to avoid entering "__hh_previous_frame" to avoid Traceback added by `tracers.LocationTracer` return default_enter(path, key, value)
def _enter(self, path, key, value): """Update contents of `merged_datasets`, `coupled_datasets`, and `leaves` and direct traversal of the sub-datasets that compose the current dataset name""" #################### Merged Datasets #################### if value in MERGED_DATASET_NAMES: self.merged_datasets.append(path + (key, )) _names_for_merge = names_for_merge(value, self.stage) return dict(), zip(_names_for_merge, _names_for_merge) #################### Coupled Datasets #################### for coupled_candidate in COUPLED_DATASET_CANDIDATES: if value == coupled_candidate[0]: self.coupled_datasets.append(path + (key, )) return dict(), zip(coupled_candidate[1:], coupled_candidate[1:]) #################### Leaf Datasets #################### if key: self.leaves[path + (key, )] = key return default_enter(path, key, value)
def enter(path, key, value): """Produce iterable of attributes to remap for instances of :class:`metrics.Metric`""" if isinstance(value, Metric): metric_attrs = ["name", "metric_function", "direction"] return ({}, [(_, getattr(value, _)) for _ in metric_attrs]) return default_enter(path, key, value)