superleaf.dataframe.column_ops#

Classes

Col(name)

Represent a named column in a DataFrame.

ColOp()

Abstract base class for column operations on pandas DataFrames.

Index()

Represent the index of a pandas DataFrame.

Values()

Represent the values of a pandas Series.

class superleaf.dataframe.column_ops.ColOp[source]#

Bases: object

Abstract base class for column operations on pandas DataFrames.

Subclasses implement transformations or evaluations that produce pandas Series or scalar results when applied to DataFrames. Supports chaining and combining using logical and arithmetic operators.

Operators defined on this class: | (bitwise or), & (bitwise and), ~ (bitwise not), == (equal to), != (not equal to), < (less than), <= (less than or equal to), > (greater than), >= (greater than or equal to), + (addition), - (subtraction), * (multiplication), / (division), ^ (power)

apply(f: Callable[[Series], Series]) ColOp[source]#

Apply a transformation function to the result of this operation.

Parameters:

f (callable) – A function that takes a pandas Series and returns a transformed Series.

Returns:

A new ColOp representing the application of f to this operation’s output.

Return type:

ColOp

map(f: Callable[[Any], Any]) ColOp[source]#

Map a function over each element of the Series produced by this operation.

Parameters:

f (callable) – A function applied element-wise to each value in the Series.

Returns:

A new ColOp representing the mapped operation.

Return type:

ColOp

isin(values: Iterable[Any]) ColOp[source]#

Test whether each element of the Series is in the given values.

Parameters:

values (iterable) – A collection of values to test membership against.

Returns:

A new ColOp that yields a boolean Series.

Return type:

ColOp

contains(value: Any) ColOp[source]#

Test whether each element of the Series contains the specified value.

Parameters:

value (Any) – Value to search for within each element.

Returns:

A new ColOp that yields a boolean Series.

Return type:

ColOp

notna() ColOp[source]#

Test for non-missing values in the Series.

Returns:

A new ColOp yielding a boolean Series where True indicates non-null values.

Return type:

ColOp

isna() ColOp[source]#

Test for missing values in the Series.

Returns:

A new ColOp yielding a boolean Series where True indicates null values.

Return type:

ColOp

astype(type_) ColOp[source]#

Cast the Series to a specified dtype.

Parameters:

type (type or str) – The target data type for the Series.

Returns:

A new ColOp representing the cast operation.

Return type:

ColOp

to_list() ColOp[source]#

Wrap each element in the Series into a single-element list.

Returns:

A new ColOp that converts each scalar to a list containing that value.

Return type:

ColOp

class superleaf.dataframe.column_ops.Index[source]#

Bases: ColOp

Represent the index of a pandas DataFrame.

Parameters:

None

Examples

>>> idx = Index()
>>> idx(df)
DatetimeIndex([...])
class superleaf.dataframe.column_ops.Col(name: str | None)[source]#

Bases: ColOp

Represent a named column in a DataFrame.

Parameters:

name (str, optional) – Column name to select. If None, selects the entire DataFrame.

Examples

>>> col = Col('column_name')
>>> col(df)
0    ...
Name: column_name, dtype: dtype
class superleaf.dataframe.column_ops.Values[source]#

Bases: Col

Represent the values of a pandas Series.

Notes

This raises a TypeError if called on a DataFrame instead of a Series.

Examples

>>> values = Values()
>>> values(series)
array([...])