Op
Sub classes¶
| Name | Children | Inherits |
|---|---|---|
| CallOp datacook.engine.ops.base An op that is one pandas call. |
||
| ColumnOp datacook.engine.ops.series The base of all per-column ops: one series per selected column, put back by `assign()`. |
||
| CustomCode datacook.engine.ops.code Python statements that read and rebind `df` (pandas is available as `pd`). |
||
| SelectColumns datacook.engine.ops.columns |
||
| MoveColumns datacook.engine.ops.columns |
||
| Downcast datacook.engine.ops.columns |
||
| DuplicateColumns datacook.engine.ops.columns |
||
| CombineColumns datacook.engine.ops.columns |
||
| Concat datacook.engine.ops.combine `pd.concat([a, b, ...])`: rows below each other (new row numbers) or side by side. |
||
| GroupByAggregate datacook.engine.ops.combine |
||
| DatetimeParts datacook.engine.ops.dates |
||
| FitTransform datacook.engine.ops.estimators Fit and apply a scikit-learn preprocessing transformer on numeric columns. |
||
| PCA datacook.engine.ops.estimators Principal component analysis on numeric columns. |
||
| Cluster datacook.engine.ops.estimators Cluster rows with KMeans or DBSCAN and add a cluster label column. |
||
| ApplyModel datacook.engine.ops.estimators Fit a scikit-learn estimator on a training table and apply it to the target table. |
||
| FillWithStatistic datacook.engine.ops.missing `df.fillna(df[cols].mean())` (one fill value per column). |
||
| FilterMissing datacook.engine.ops.missing |
||
| NanToMissing datacook.engine.ops.missing `df.mask(lambda d: d !\= d)`: NaN is the only value not equal to itself. |
||
| Crosstab datacook.engine.ops.reshape `pd.crosstab([df["a"], ...], df["b"])`: counts per combination of values. |
||
| Transpose datacook.engine.ops.reshape Rows become columns: `df.set_index("name").transpose().reset_index(names\="column")`. |
||
| SliceRows datacook.engine.ops.rows |
||
| FilterIsIn datacook.engine.ops.rows |
||
| ReadSqlite datacook.engine.ops.sources `pd.read_sql_query(query, sqlite3.connect(path))`. |
||
| InlineData datacook.engine.ops.sources A small table typed in (or pasted) by the user, stored in the project. |
||
| FilterText datacook.engine.ops.strings |
||
_ExpandOpdatacook.engine.ops.strings Text -> several new columns: `df.join(df["a"].str.<method>(...).add_prefix("a_"))`. |
||
| SetTimeColumn datacook.engine.ops.timeseries |
||
| Resample datacook.engine.ops.timeseries |
||
| Upsample datacook.engine.ops.timeseries |
||
| SecondsSinceStart datacook.engine.ops.timeseries Old pandastools `index_to_secs`, as a column. |
||
| DetectGaps datacook.engine.ops.timeseries Old pandastools `detect_gaps` / time gaps, on a column. |
||
| ToleranceBands datacook.engine.ops.timeseries Old pandastools `tolerance_bands`: lower \= min(rolling min, x * (1 - pct)), upper alike. |
||
| ReplaceValues datacook.engine.ops.values `df.replace(old, new)`; new \= None replaces with a missing value (`pd.NA`). |
🛈 DocStrings¶
Base class for operations. Subclasses set the metadata class variables.
Source code in src/datacook/engine/ops/base.py
imports
class-attribute
¶
Import lines the generated code needs.
n_inputs
class-attribute
¶
Number of parent frames: 0 = source (reader), 2 = merge, ...
requires
class-attribute
¶
Importable modules needed at runtime (optional dependencies).
from_block
classmethod
¶
from_block(stmts: Sequence[stmt], bound: Mapping[str, Any]) -> Match | None
Recognise a multi-statement block produced by to_code (default: none).
from_code
classmethod
¶
from_code(stmt: stmt, bound: Mapping[str, Any]) -> Match | None
Recognise one statement produced by to_code; bound = known variable names.
Return None if the statement is not this op. Raise ValueError for a recognised
statement with invalid params.
Source code in src/datacook/engine/ops/base.py
imports_for
classmethod
¶
Import lines the generated code needs for params (default: cls.imports).
inputs_text
classmethod
¶
takes
classmethod
¶
to_code
classmethod
¶
Python statement(s) computing output from the input variables.
to_code_block
classmethod
¶
Like to_code, with the script's already-used variable names (for unique locals).