tslumen.profile.base module

Base functionality for the profile package, including a dataclass for representing results and a decorator for allowing profiling functions to be employed correctly, as well as automatically capturing execution information.

class tslumen.profile.base.BundledProfiler(config: Optional[Dict[str, Dict[str, Any]]] = None, scheduler: Optional[tslumen.scheduling.Scheduler] = None)[source]

Bases: object

Base class for creating bundled profilers.

Contains functionality to manage configurations, orchestrate the execution of the profiling functions and collate the results. It’s up for the subclasses to decide on which profiling functions to include, done so by assigning a list with said profiling functions to the class variable _profilers.

Parameters
  • config (Optional[dict]) – Profiler functions’ configurations. Whatever options are provided here will override the defaults. Expects a 2-level dictionary with the first level indexed by the name of the profiling functions and the second level the function’s parameters. Assumed configs (i.e. defaults + overrides) are stored in the class variable config.

  • scheduler (Optional[Scheduler]) – For executing the profiling functions. Instantiates the default one if not provided.

classmethod get_config_defaults(as_dict: bool = True)Dict[str, Any][source]
Returns

Bundled configurations (defaults), profiler name => configuration.

Return type

dict

classmethod get_profilers(target: str = 'any')Dict[str, tslumen.profile.base.ProfilingFunction][source]
Parameters

target – {‘series’, ‘frame’, ‘any’}, default ‘any’ Filter by function target (single series, data frame, or any/no filter).

Returns

Bundled profilers, profiler name => profiler function.

Return type

dict

profile(df: pandas.core.frame.DataFrame)tslumen.profile.base.BundledResult[source]

Executes the profiling functions on the supplied DataFrame.

Parameters

df (pd.DataFrame) – TimeSeries data to be profiled.

Returns

Result of the profiling.

Return type

ProfileResult

class tslumen.profile.base.BundledResult[source]

Bases: tslumen.profile.base.ProfileResult

result: tslumen.profile.base.BundledResultDetails
class tslumen.profile.base.BundledResultDetails[source]

Bases: tslumen.profile.base._DCDict

config: Dict[str, Dict[str, Any]]
exec_details: pandas.core.frame.DataFrame
frame: Dict[str, Any]
series: Dict[str, Dict[str, Any]]
exception tslumen.profile.base.ProfileException[source]

Bases: BaseException

class tslumen.profile.base.ProfileResult[source]

Bases: tslumen.profile.base._DCDict

For recording the results of a profiling operation.

end: datetime.datetime
exception: Optional[tslumen.profile.base.ProfileException]
name: str
result: Optional[Any]
scope: str
start: datetime.datetime
success: bool
target: str
warnings: List[warnings.WarningMessage]
class tslumen.profile.base.ProfilingFunction(fn: Callable)[source]

Bases: object

Decorator for turning a function into a profiler. Inspects the function’s signature and builds a dataclass representing its configurations (for integrating with Hydra). Adds two attributes is_pseries and is_pframe to distinguish whether it targets Series or DataFrames. This is inferred based on the type annotation of the first parameter. Captures the start and end timestamps, the return value, as well as any warnings or exceptions raised during the execution.

Parameters

fn (Callable) – Profiler function to decorate.

config: Any
fn: Callable
is_pframe: bool = False
is_pseries: bool = False
sig: inspect.Signature
tslumen.profile.base.valid_timeseries(df: pandas.core.frame.DataFrame)pandas.core.frame.DataFrame[source]

Checks if the DataFrame meets the necessary criteria to be profiled: be a Pandas DataFrame, have values (must be numeric), have a DateTimeIndex, have a recognizable frequency/period.

Parameters

df – Pandas DataFrame.

Returns

A copy of the input containing only numeric series and a sorted index.

Return type

pandas.DataFrame