narwhals API reference
395 public APIs from narwhals (narwhals-dev/narwhals) — 57 classes, 115 functions, 223 methods. Signatures extracted by static analysis of the actual source.
Repository: narwhals-dev/narwhals
| Kind | Count |
|---|---|
| Classes | 57 |
| Functions | 115 |
| Methods | 223 |
API list
func
src.narwhals._arrow.utils.is_array_or_scalar(obj:Any) -> TypeIs[ArrayOrScalar]Return True for any base `pyarrow` container.
func
src.narwhals._arrow.utils.nulls_like(n:int, series:ArrowSeries) -> ArrayAnyCreate a strongly-typed Array instance with all elements null.
func
src.narwhals._arrow.utils.parse_datetime_format(arr:ChunkedArrayAny) -> strTry to infer datetime format from StringArray.
class
src.narwhals._compliant.column.CompliantColumnCommon parts of `Expr`, `Series`.
class
src.narwhals._compliant.dataframe.CompliantFrameCommon parts of `DataFrame`, `LazyFrame`.
method
src.narwhals._compliant.dataframe.CompliantFrame.simple_select(*column_names:str) -> Self`select` where all args are column names.
class
src.narwhals._compliant.namespace.AlignDiagonalMixin to help support `"diagonal*"` concatenation.
func
src.narwhals._duckdb.utils.concat_str(*separator:str='', *exprs:Expression) -> ExpressionConcatenate many strings, NULL inputs are skipped.
func
src.narwhals._duckdb.utils.lambda_expr(params:str | Expression | tuple[Expression, ...], expr:Expression) -> ExpressionWraps [`duckdb.LambdaExpression`].
func
src.narwhals._exceptions.issue_deprecation_warning(message:str, _version:str) -> NoneIssue a deprecation warning.
class
src.narwhals._expression_parsing.ExprKindDescribe which kind of expression we are dealing with.
class
src.narwhals._expression_parsing.ExprMetadataExpression metadata.
class
src.narwhals._expression_parsing.ExprNodeAn operation to create or modify an expression.
func
src.narwhals._expression_parsing.combine_metadata(*to_single_output:bool, *current_node:ExprNode, *prev:ExprMetadata | None, *compliant_exprs:CompliantExprAny) -> ExprMetadataCombine metadata from `args`.
func
src.narwhals._expression_parsing.is_expr(obj:Any) -> TypeIs[Expr]Check whether `obj` is a Narwhals Expr.
func
src.narwhals._expression_parsing.is_series(obj:Any) -> TypeIs[Series[Any]]Check whether `obj` is a Narwhals Expr.
func
src.narwhals._pandas_like.utils.align_and_extract_native(lhs:PandasLikeSeries, rhs:PandasLikeSeries | object) -> tuple[pd.Series[Any], pd.Series[Any] | object]Validate RHS of binary operation.
func
src.narwhals._pandas_like.utils.get_dtype_backend(dtype:Any, implementation:Implementation) -> DTypeBackendGet dtype backend for pandas type.
func
src.narwhals._pandas_like.utils.is_dtype_numpy_nullable(dtype:Any) -> TypeIs[BaseMaskedDtype]Return `True` if `dtype` is `"numpy_nullable"`.
func
src.narwhals._pandas_like.utils.iter_dtype_backends(dtypes:Iterable[Any], implementation:Implementation) -> Iterator[DTypeBackend]Yield a `DTypeBackend` per-dtype.
func
src.narwhals._pandas_like.utils.select_columns_by_name(df:NativeDataFrameT, column_names:list[str] | _1DArray, implementation:Implementation) -> NativeDataFrameT | AnySelect columns by name.
func
src.narwhals._pandas_like.utils.set_index(obj:NativeNDFrameT, index:Any, *implementation:Implementation) -> NativeNDFrameTWrapper around pandas' set_axis to set object index.
method
src.narwhals._utils.Implementation.is_cudf() -> boolReturn whether implementation is cuDF.
method
src.narwhals._utils.Implementation.is_dask() -> boolReturn whether implementation is Dask.
method
src.narwhals._utils.Implementation.is_duckdb() -> boolReturn whether implementation is DuckDB.
method
src.narwhals._utils.Implementation.is_ibis() -> boolReturn whether implementation is Ibis.
method
src.narwhals._utils.Implementation.is_modin() -> boolReturn whether implementation is Modin.
method
src.narwhals._utils.Implementation.is_pandas() -> boolReturn whether implementation is pandas.
method
src.narwhals._utils.Implementation.is_polars() -> boolReturn whether implementation is Polars.
method
src.narwhals._utils.Implementation.is_pyarrow() -> boolReturn whether implementation is PyArrow.
method
src.narwhals._utils.Implementation.is_pyspark() -> boolReturn whether implementation is PySpark.
method
src.narwhals._utils.Implementation.is_pyspark_connect() -> boolReturn whether implementation is PySpark.
method
src.narwhals._utils.Implementation.is_spark_like() -> boolReturn whether implementation is pyspark or sqlframe.
method
src.narwhals._utils.Implementation.is_sqlframe() -> boolReturn whether implementation is SQLFrame.
class
src.narwhals._utils.NarwhalsMinimal *Narwhals-level* protocol.
func
src.narwhals._utils.can_lazyframe_collect(impl:Implementation) -> TypeIs[_LazyFrameCollectImpl]Return True if `LazyFrame.collect(impl)` is allowed.
func
src.narwhals._utils.deep_getattr(obj:Any, name_1:str, *nested:str) -> AnyPerform a nested attribute lookup on `obj`.
func
src.narwhals._utils.is_eager_allowed(impl:Implementation) -> TypeIs[_EagerAllowedImpl]Return True if `impl` allows eager operations.
func
src.narwhals._utils.is_lazy_allowed(impl:Implementation) -> TypeIs[_LazyAllowedImpl]Return True if `DataFrame.lazy(impl)` is allowed.
class
src.narwhals._utils.not_implementedMark some functionality as unsupported.
method
src.narwhals._utils.not_implemented.deprecated(message:LiteralString) -> SelfAlt constructor, wraps with `@deprecated`.
class
src.narwhals._utils.requiresMethod decorator for raising under certain constraints.
func
src.narwhals._utils.unstable(fn:_Fn) -> _FnVisual-only marker for unstable functionality.
class
src.narwhals.dataframe.DataFrameNarwhals DataFrame, backed by a native eager dataframe.
method
src.narwhals.dataframe.DataFrame.clone() -> SelfCreate a copy of this DataFrame.
method
src.narwhals.dataframe.DataFrame.columns() -> list[str]Get column names.
method
src.narwhals.dataframe.DataFrame.drop(*strict:bool=True, *columns:str | Iterable[str]) -> SelfRemove columns from the dataframe.
method
src.narwhals.dataframe.DataFrame.drop_nulls(subset:str | list[str] | None=None) -> SelfDrop rows that contain null values.
method
src.narwhals.dataframe.DataFrame.get_column(name:str) -> Series[Any]Get a single column by name.
method
src.narwhals.dataframe.DataFrame.head(n:int=5) -> SelfGet the first `n` rows.
method
src.narwhals.dataframe.DataFrame.is_empty() -> boolCheck if the dataframe is empty.
method
src.narwhals.dataframe.DataFrame.is_unique() -> Series[Any]Get a mask of all unique rows in this DataFrame.
method
src.narwhals.dataframe.DataFrame.join(other:Self, on:str | list[str] | None=None, how:JoinStrategy='inner', *left_on:str | list[str] | None=None, *right_on:str | list[str] | None=None, *suffix:str='_right') -> SelfJoin in SQL-like fashion.
method
src.narwhals.dataframe.DataFrame.lazy(backend:IntoBackend[LazyAllowed] | None=None, *session:Any | None=None) -> LazyFrame[Any]Restrict available API methods to lazy-only ones.
method
src.narwhals.dataframe.DataFrame.pipe(function:Callable[Concatenate[Self, PS], R], *args:PS.args, **kwargs:PS.kwargs) -> RPipe function call.
method
src.narwhals.dataframe.DataFrame.rename(mapping:dict[str, str]) -> SelfRename column names.
method
src.narwhals.dataframe.DataFrame.row(index:int) -> tuple[Any, ...]Get values at given row.
method
src.narwhals.dataframe.DataFrame.sample(n:int | None=None, *fraction:float | None=None, *with_replacement:bool=False, *seed:int | None=None) -> SelfSample from this DataFrame.
method
src.narwhals.dataframe.DataFrame.select(*exprs:IntoExpr | Iterable[IntoExpr], **named_exprs:IntoExpr) -> SelfSelect columns from this DataFrame.
method
src.narwhals.dataframe.DataFrame.shape() -> tuple[int, int]Get the shape of the DataFrame.
method
src.narwhals.dataframe.DataFrame.sort(by:str | Iterable[str], *descending:bool | Sequence[bool]=False, *nulls_last:bool=False, *more_by:str) -> SelfSort the dataframe by the given columns.
method
src.narwhals.dataframe.DataFrame.tail(n:int=5) -> SelfGet the last `n` rows.
method
src.narwhals.dataframe.DataFrame.to_arrow() -> pa.TableConvert to arrow table.
method
src.narwhals.dataframe.DataFrame.to_native() -> DataFrameTConvert Narwhals DataFrame to native one.
method
src.narwhals.dataframe.DataFrame.to_numpy() -> _2DArrayConvert this DataFrame to a NumPy ndarray.
method
src.narwhals.dataframe.DataFrame.to_pandas() -> pd.DataFrameConvert this DataFrame to a pandas DataFrame.
method
src.narwhals.dataframe.DataFrame.to_polars() -> pl.DataFrameConvert this DataFrame to a polars DataFrame.
method
src.narwhals.dataframe.DataFrame.top_k(k:int, *by:str | Iterable[str], *reverse:bool | Sequence[bool]=False) -> SelfReturn the `k` largest rows.
method
src.narwhals.dataframe.DataFrame.with_columns(*exprs:IntoExpr | Iterable[IntoExpr], **named_exprs:IntoExpr) -> SelfAdd columns to this DataFrame.
method
src.narwhals.dataframe.DataFrame.with_row_index(name:str='index', *order_by:str | Sequence[str] | None=None) -> SelfInsert column which enumerates rows.
method
src.narwhals.dataframe.DataFrame.write_parquet(file:str | Path | BytesIO) -> NoneWrite dataframe to parquet file.
class
src.narwhals.dataframe.LazyFrameNarwhals LazyFrame, backed by a native lazyframe.
method
src.narwhals.dataframe.LazyFrame.collect(backend:IntoBackend[Polars | Pandas | Arrow] | None=None, **kwargs:Any) -> DataFrame[Any]Materialize this LazyFrame into a DataFrame.
method
src.narwhals.dataframe.LazyFrame.columns() -> list[str]Get column names.
method
src.narwhals.dataframe.LazyFrame.drop(*strict:bool=True, *columns:str | Iterable[str]) -> SelfRemove columns from the LazyFrame.
method
src.narwhals.dataframe.LazyFrame.drop_nulls(subset:str | list[str] | None=None) -> SelfDrop rows that contain null values.
method
src.narwhals.dataframe.LazyFrame.head(n:int=5) -> SelfGet `n` rows.
method
src.narwhals.dataframe.LazyFrame.lazy() -> SelfRestrict available API methods to lazy-only ones.
method
src.narwhals.dataframe.LazyFrame.pipe(function:Callable[Concatenate[Self, PS], R], *args:PS.args, **kwargs:PS.kwargs) -> RPipe function call.
method
src.narwhals.dataframe.LazyFrame.rename(mapping:dict[str, str]) -> SelfRename column names.
method
src.narwhals.dataframe.LazyFrame.select(*exprs:IntoExpr | Iterable[IntoExpr], **named_exprs:IntoExpr) -> SelfSelect columns from this LazyFrame.
method
src.narwhals.dataframe.LazyFrame.sink_parquet(file:str | Path | BytesIO) -> NoneWrite LazyFrame to Parquet file.
method
src.narwhals.dataframe.LazyFrame.sort(by:str | Iterable[str], *descending:bool | Sequence[bool]=False, *nulls_last:bool=False, *more_by:str) -> SelfSort the LazyFrame by the given columns.
method
src.narwhals.dataframe.LazyFrame.to_native() -> LazyFrameTConvert Narwhals LazyFrame to native one.
method
src.narwhals.dataframe.LazyFrame.top_k(k:int, *by:str | Iterable[str], *reverse:bool | Sequence[bool]=False) -> SelfReturn the `k` largest rows.
method
src.narwhals.dataframe.LazyFrame.unique(subset:str | list[str] | None=None, *keep:UniqueKeepStrategy='any', *order_by:str | Sequence[str] | None=None) -> SelfDrop duplicate rows from this LazyFrame.
method
src.narwhals.dataframe.LazyFrame.with_columns(*exprs:IntoExpr | Iterable[IntoExpr], **named_exprs:IntoExpr) -> SelfAdd columns to this LazyFrame.
method
src.narwhals.dataframe.LazyFrame.with_row_index(name:str='index', *order_by:str | Sequence[str]) -> SelfInsert column which enumerates rows.
func
src.narwhals.dependencies.get_cudf() -> AnyGet cudf module (if already imported - else return None).
func
src.narwhals.dependencies.get_cupy() -> AnyGet cupy module (if already imported - else return None).
func
src.narwhals.dependencies.get_dask() -> AnyGet dask (if already imported - else return None).
func
src.narwhals.dependencies.get_ibis() -> AnyGet ibis module (if already imported - else return None).
func
src.narwhals.dependencies.get_numpy() -> AnyGet numpy module (if already imported - else return None).
func
src.narwhals.dependencies.get_pandas() -> AnyGet pandas module (if already imported - else return None).
func
src.narwhals.dependencies.is_cudf_index(index:Any) -> TypeIs[cudf.Index]Check whether `index` is a cudf Index without importing cudf.
func
src.narwhals.dependencies.is_cudf_series(ser:Any) -> TypeIs[cudf.Series[Any]]Check whether `ser` is a cudf Series without importing cudf.
func
src.narwhals.dependencies.is_dask_dataframe(df:Any) -> TypeIs[dd.DataFrame]Check whether `df` is a Dask DataFrame without importing Dask.
func
src.narwhals.dependencies.is_ibis_table(df:Any) -> TypeIs[ibis.Table]Check whether `df` is a Ibis Table without importing Ibis.
func
src.narwhals.dependencies.is_modin_series(ser:Any) -> TypeIs[mpd.Series]Check whether `ser` is a modin Series without importing modin.
func
src.narwhals.dependencies.is_narwhals_dataframe(df:DataFrame[IntoDataFrameT] | Any) -> TypeIs[DataFrame[IntoDataFrameT]]Check whether `df` is a Narwhals DataFrame.
func
src.narwhals.dependencies.is_narwhals_lazyframe(lf:Any | LazyFrame[IntoLazyFrameT]) -> TypeIs[LazyFrame[IntoLazyFrameT]]Check whether `lf` is a Narwhals LazyFrame.
func
src.narwhals.dependencies.is_narwhals_series(ser:Any | Series[IntoSeriesT]) -> TypeIs[Series[IntoSeriesT]]Check whether `ser` is a Narwhals Series.
func
src.narwhals.dependencies.is_numpy_array(arr:Any | _NDArray[_ShapeT]) -> TypeIs[_NDArray[_ShapeT]]Check whether `arr` is a NumPy Array without importing NumPy.
func
src.narwhals.dependencies.is_numpy_array_1d(arr:Any) -> TypeIs[_1DArray]Check whether `arr` is a 1D NumPy Array without importing NumPy.
func
src.narwhals.dependencies.is_numpy_array_2d(arr:Any) -> TypeIs[_2DArray]Check whether `arr` is a 2D NumPy Array without importing NumPy.
func
src.narwhals.dependencies.is_pyarrow_table(df:Any) -> TypeIs[pa.Table]Check whether `df` is a PyArrow Table without importing PyArrow.
class
src.narwhals.dtypes.ArrayFixed length list type.
class
src.narwhals.dtypes.BinaryBinary type.
class
src.narwhals.dtypes.BooleanBoolean type.
class
src.narwhals.dtypes.CategoricalA categorical encoding of a set of strings.
class
src.narwhals.dtypes.DTypeBase class for all Narwhals data types.
method
src.narwhals.dtypes.DType.base_type() -> type[Self]Return this DType's fundamental/root type class.
method
src.narwhals.dtypes.DType.is_boolean() -> boolCheck whether the data type is a boolean type.
method
src.narwhals.dtypes.DType.is_decimal() -> boolCheck whether the data type is a decimal type.
method
src.narwhals.dtypes.DType.is_float() -> boolCheck whether the data type is a floating point type.
method
src.narwhals.dtypes.DType.is_integer() -> boolCheck whether the data type is an integer type.
method
src.narwhals.dtypes.DType.is_nested() -> boolCheck whether the data type is a nested type.
method
src.narwhals.dtypes.DType.is_numeric() -> boolCheck whether the data type is a numeric type.
method
src.narwhals.dtypes.DType.is_signed_integer() -> boolCheck whether the data type is a signed integer type.
method
src.narwhals.dtypes.DType.is_temporal() -> boolCheck whether the data type is a temporal type.
class
src.narwhals.dtypes.DTypeClassMetaclass for DType classes.
class
src.narwhals.dtypes.DateData type representing a calendar date.
class
src.narwhals.dtypes.DatetimeData type representing a calendar date and time of day.
class
src.narwhals.dtypes.DurationData type representing a time duration.
class
src.narwhals.dtypes.EnumA fixed categorical encoding of a unique set of strings.
method
src.narwhals.dtypes.Enum.categories() -> tuple[str, ...]The categories in the dataset.
class
src.narwhals.dtypes.FieldDefinition of a single field within a `Struct` DType.
class
src.narwhals.dtypes.Float1616-bit floating point type.
class
src.narwhals.dtypes.Float3232-bit floating point type.
class
src.narwhals.dtypes.Float6464-bit floating point type.
class
src.narwhals.dtypes.FloatTypeBase class for float data types.
class
src.narwhals.dtypes.Int128128-bit signed integer type.
class
src.narwhals.dtypes.Int1616-bit signed integer type.
class
src.narwhals.dtypes.Int3232-bit signed integer type.
class
src.narwhals.dtypes.Int6464-bit signed integer type.
class
src.narwhals.dtypes.Int88-bit signed integer type.
class
src.narwhals.dtypes.IntegerTypeBase class for integer data types.
class
src.narwhals.dtypes.ListVariable length list type.
class
src.narwhals.dtypes.NestedTypeBase class for nested data types.
class
src.narwhals.dtypes.NumericTypeBase class for numeric data types.
class
src.narwhals.dtypes.ObjectData type for wrapping arbitrary Python objects.
class
src.narwhals.dtypes.SignedIntegerTypeBase class for signed integer data types.
class
src.narwhals.dtypes.StringUTF-8 encoded string type.
class
src.narwhals.dtypes.StructStruct composite type.
method
src.narwhals.dtypes.Struct.to_schema() -> OrderedDict[str, IntoDType]Return Struct dtype as a schema dict.
class
src.narwhals.dtypes.TemporalTypeBase class for temporal data types.
class
src.narwhals.dtypes.TimeData type representing the time of day.
class
src.narwhals.dtypes.UInt128128-bit unsigned integer type.
class
src.narwhals.dtypes.UInt1616-bit unsigned integer type.
class
src.narwhals.dtypes.UInt3232-bit unsigned integer type.
class
src.narwhals.dtypes.UInt6464-bit unsigned integer type.
class
src.narwhals.dtypes.UInt88-bit unsigned integer type.
class
src.narwhals.dtypes.UnsignedIntegerTypeBase class for unsigned integer data types.
class
src.narwhals.exceptions.ColumnNotFoundErrorException raised when column name isn't present.
class
src.narwhals.exceptions.DuplicateErrorException when duplicate column names are encountered.
class
src.narwhals.exceptions.FormattedKeyErrorKeyError with formatted error message.
class
src.narwhals.exceptions.InvalidOperationErrorException raised during invalid operations.
class
src.narwhals.exceptions.NarwhalsErrorBase class for all Narwhals exceptions.
method
src.narwhals.expr.Expr.abs() -> SelfReturn absolute value of each element.
method
src.narwhals.expr.Expr.alias(name:str) -> SelfRename the expression.
method
src.narwhals.expr.Expr.all() -> SelfReturn whether all values in the column are `True`.
method
src.narwhals.expr.Expr.any() -> SelfReturn whether any of the values in the column are `True`.
method
src.narwhals.expr.Expr.any_value(*ignore_nulls:bool=False) -> SelfGet a random value from the column.
method
src.narwhals.expr.Expr.cast(dtype:IntoDType) -> SelfRedefine an object's data type.
method
src.narwhals.expr.Expr.ceil() -> SelfCompute the numerical ceiling.
method
src.narwhals.expr.Expr.clip(lower_bound:IntoExpr | NumericLiteral | TemporalLiteral | None=None, upper_bound:IntoExpr | NumericLiteral | TemporalLiteral | None=None) -> SelfClip values in the Series.
method
src.narwhals.expr.Expr.cos() -> SelfCompute the element-wise value for the cosine.
method
src.narwhals.expr.Expr.count() -> SelfReturns the number of non-null elements in the column.
method
src.narwhals.expr.Expr.cum_count(*reverse:bool=False) -> SelfReturn the cumulative count of the non-null values in the column.
method
src.narwhals.expr.Expr.cum_max(*reverse:bool=False) -> SelfReturn the cumulative max of the non-null values in the column.
method
src.narwhals.expr.Expr.cum_min(*reverse:bool=False) -> SelfReturn the cumulative min of the non-null values in the column.
method
src.narwhals.expr.Expr.cum_prod(*reverse:bool=False) -> SelfReturn the cumulative product of the non-null values in the column.
method
src.narwhals.expr.Expr.cum_sum(*reverse:bool=False) -> SelfReturn cumulative sum.
method
src.narwhals.expr.Expr.drop_nulls() -> SelfDrop null values.
method
src.narwhals.expr.Expr.exp() -> SelfCompute the exponent.
method
src.narwhals.expr.Expr.fill_nan(value:float | None) -> SelfFill floating point NaN values with given value.
method
src.narwhals.expr.Expr.fill_null(value:Expr | NonNestedLiteral=None, strategy:FillNullStrategy | None=None, limit:int | None=None) -> SelfFill null values with given value.
method
src.narwhals.expr.Expr.filter(*predicates:Any) -> SelfFilters elements based on a condition, returning a new expression.
method
src.narwhals.expr.Expr.first(order_by:str | Iterable[str] | None=None) -> SelfGet the first value.
method
src.narwhals.expr.Expr.floor() -> SelfCompute the numerical floor.
method
src.narwhals.expr.Expr.is_close(other:Expr | Series[Any] | NumericLiteral, *abs_tol:float=0.0, *rel_tol:float=1e-09, *nans_equal:bool=False) -> SelfCheck if this expression is close, i.e.
method
src.narwhals.expr.Expr.is_duplicated() -> SelfReturn a boolean mask indicating duplicated values.
method
src.narwhals.expr.Expr.is_in(other:Any) -> SelfCheck if elements of this expression are present in the other iterable.
method
src.narwhals.expr.Expr.is_nan() -> SelfIndicate which values are NaN.
method
src.narwhals.expr.Expr.is_null() -> SelfReturns a boolean Series indicating which values are null.
method
src.narwhals.expr.Expr.is_unique() -> SelfReturn a boolean mask indicating unique values.
method
src.narwhals.expr.Expr.last(order_by:str | Iterable[str] | None=None) -> SelfGet the last value.
method
src.narwhals.expr.Expr.len() -> SelfReturn the number of elements in the column.
method
src.narwhals.expr.Expr.log(base:float=math.e) -> SelfCompute the logarithm to a given base.
method
src.narwhals.expr.Expr.max() -> SelfReturns the maximum value(s) from a column(s).
method
src.narwhals.expr.Expr.mean() -> SelfGet mean value.
method
src.narwhals.expr.Expr.median() -> SelfGet median value.
method
src.narwhals.expr.Expr.min() -> SelfReturns the minimum value(s) from a column(s).
method
src.narwhals.expr.Expr.mode(*keep:ModeKeepStrategy='all') -> SelfCompute the most occurring value(s).
method
src.narwhals.expr.Expr.n_unique() -> SelfReturns count of unique values.
method
src.narwhals.expr.Expr.null_count() -> SelfCount null values.
method
src.narwhals.expr.Expr.pipe(function:Callable[Concatenate[Self, PS], R], *args:PS.args, **kwargs:PS.kwargs) -> RPipe function call.
method
src.narwhals.expr.Expr.quantile(quantile:float, interpolation:RollingInterpolationMethod) -> SelfGet quantile value.
method
src.narwhals.expr.Expr.rank(method:RankMethod='average', *descending:bool=False) -> SelfAssign ranks to data, dealing with ties appropriately.
method
src.narwhals.expr.Expr.rolling_mean(window_size:int, *min_samples:int | None=None, *center:bool=False) -> SelfApply a rolling mean (moving mean) over the values.
method
src.narwhals.expr.Expr.rolling_sum(window_size:int, *min_samples:int | None=None, *center:bool=False) -> SelfApply a rolling sum (moving sum) over the values.
method
src.narwhals.expr.Expr.round(decimals:int=0) -> SelfRound underlying floating point data by `decimals` digits.
method
src.narwhals.expr.Expr.shift(n:int) -> SelfShift values by `n` positions.
method
src.narwhals.expr.Expr.sin() -> SelfCompute the element-wise value for the sine.
method
src.narwhals.expr.Expr.skew() -> SelfCalculate the sample skewness of a column.
method
src.narwhals.expr.Expr.sqrt() -> SelfCompute the square root of the elements.
method
src.narwhals.expr.Expr.std(*ddof:int=1) -> SelfGet standard deviation.
method
src.narwhals.expr.Expr.sum() -> SelfReturn the sum value.
method
src.narwhals.expr.Expr.unique() -> SelfReturn unique values of this expression.
method
src.narwhals.expr.Expr.var(*ddof:int=1) -> SelfGet variance.
func
src.narwhals.functions.all_() -> ExprInstantiate an expression representing all columns.
func
src.narwhals.functions.all_horizontal(*ignore_nulls:bool, *exprs:IntoExpr | Iterable[IntoExpr]) -> ExprCompute the bitwise AND horizontally across columns.
func
src.narwhals.functions.any_horizontal(*ignore_nulls:bool, *exprs:IntoExpr | Iterable[IntoExpr]) -> ExprCompute the bitwise OR horizontally across columns.
func
src.narwhals.functions.cov(a:IntoExpr, b:IntoExpr, *ddof:int=1) -> ExprCompute the covariance between two columns.
func
src.narwhals.functions.exclude(*names:str | Iterable[str]) -> ExprCreates an expression that excludes columns by their name(s).
func
src.narwhals.functions.format(f_string:str, *args:IntoExpr) -> ExprFormat expressions as a string.
func
src.narwhals.functions.len_() -> ExprReturn the number of rows.
func
src.narwhals.functions.list_(*exprs:IntoExpr | Sequence[IntoExpr]) -> ExprCollect columns into a list column.
func
src.narwhals.functions.lit(value:PythonLiteral, dtype:IntoDType | None=None) -> ExprReturn an expression representing a literal value.
func
src.narwhals.functions.max(*columns:str) -> ExprReturn the maximum value.
func
src.narwhals.functions.max_horizontal(*exprs:IntoExpr | Iterable[IntoExpr]) -> ExprGet the maximum value horizontally across columns.
func
src.narwhals.functions.mean(*columns:str) -> ExprGet the mean value.
func
src.narwhals.functions.mean_horizontal(*exprs:IntoExpr | Iterable[IntoExpr]) -> ExprCompute the mean of all values horizontally across columns.
func
src.narwhals.functions.median(*columns:str) -> ExprGet the median value.
func
src.narwhals.functions.min(*columns:str) -> ExprReturn the minimum value.
func
src.narwhals.functions.min_horizontal(*exprs:IntoExpr | Iterable[IntoExpr]) -> ExprGet the minimum value horizontally across columns.
func
src.narwhals.functions.new_series(name:str, values:Any, dtype:IntoDType | None=None, *backend:IntoBackend[EagerAllowed | PluginName]) -> Series[Any]Instantiate Narwhals Series from iterable (e.g.
func
src.narwhals.functions.read_csv(source:FileSource, *backend:IntoBackend[EagerAllowed | PluginName], *separator:str=',', **kwargs:Any) -> DataFrame[Any]Read a CSV file into a DataFrame.
func
src.narwhals.functions.read_parquet(source:FileSource, *backend:IntoBackend[EagerAllowed | PluginName], **kwargs:Any) -> DataFrame[Any]Read into a DataFrame from a parquet file.
func
src.narwhals.functions.scan_csv(source:FileSource, *backend:IntoBackend[Backend | PluginName], *separator:str=',', **kwargs:Any) -> LazyFrame[Any]Lazily read from a CSV file.
func
src.narwhals.functions.scan_parquet(source:FileSource, *backend:IntoBackend[Backend | PluginName], **kwargs:Any) -> LazyFrame[Any]Lazily read from a parquet file.
func
src.narwhals.functions.show_versions() -> NonePrint useful debugging information.
func
src.narwhals.functions.struct(*exprs:IntoExpr | Sequence[IntoExpr], **named_exprs:IntoExpr) -> ExprCollect columns into a struct column.
func
src.narwhals.functions.sum(*columns:str) -> ExprSum all values.
func
src.narwhals.functions.sum_horizontal(*exprs:IntoExpr | Iterable[IntoExpr]) -> ExprSum all values horizontally across columns.
func
src.narwhals.functions.when(*predicates:IntoExpr | Iterable[IntoExpr]) -> WhenStart a `when-then-otherwise` expression.
class
src.narwhals.schema.SchemaOrdered mapping of column names to their data type.
method
src.narwhals.schema.Schema.dtypes() -> list[DType]Get the data types of the schema.
method
src.narwhals.schema.Schema.from_arrow(schema:IntoArrowSchema) -> SelfConstruct a Schema from a pyarrow Schema.
method
src.narwhals.schema.Schema.from_native(schema:IntoArrowSchema | IntoPolarsSchema | IntoPandasSchema) -> SelfConstruct a Schema from a native schema representation.
method
src.narwhals.schema.Schema.from_pandas_like(schema:IntoPandasSchema) -> SelfConstruct a Schema from a pandas-like schema representation.
method
src.narwhals.schema.Schema.from_polars(schema:IntoPolarsSchema) -> SelfConstruct a Schema from a polars Schema.
method
src.narwhals.schema.Schema.len() -> intGet the number of columns in the schema.
method
src.narwhals.schema.Schema.names() -> list[str]Get the column names of the schema.
method
src.narwhals.schema.Schema.to_arrow() -> pa.SchemaConvert Schema to a pyarrow Schema.
method
src.narwhals.schema.Schema.to_polars() -> pl.SchemaConvert Schema to a polars Schema.
func
src.narwhals.selectors.all() -> SelectorSelect all columns.
func
src.narwhals.selectors.boolean() -> SelectorSelect boolean columns.
func
src.narwhals.selectors.by_dtype(*dtypes:DType | type[DType] | Iterable[DType | type[DType]]) -> SelectorSelect columns based on their dtype.
func
src.narwhals.selectors.categorical() -> SelectorSelect categorical columns.
func
src.narwhals.selectors.enum() -> SelectorSelect enum columns.
func
src.narwhals.selectors.matches(pattern:str) -> SelectorSelect all columns that match the given regex pattern.
func
src.narwhals.selectors.numeric() -> SelectorSelect numeric columns.
func
src.narwhals.selectors.string() -> SelectorSelect string columns.
class
src.narwhals.series.SeriesNarwhals Series, backed by a native series.
method
src.narwhals.series.Series.abs() -> SelfCalculate the absolute value of each element.
method
src.narwhals.series.Series.alias(name:str) -> SelfRename the Series.
method
src.narwhals.series.Series.all() -> boolReturn whether all values in the Series are True.
method
src.narwhals.series.Series.any() -> boolReturn whether any of the values in the Series are True.
method
src.narwhals.series.Series.any_value(*ignore_nulls:bool=False) -> PythonLiteralGet a random value from the column.
method
src.narwhals.series.Series.arg_max() -> intReturns the index of the maximum value.
method
src.narwhals.series.Series.arg_min() -> intReturns the index of the minimum value.
method
src.narwhals.series.Series.arg_true() -> SelfFind elements where boolean Series is True.
method
src.narwhals.series.Series.cast(dtype:IntoDType) -> SelfCast between data types.
method
src.narwhals.series.Series.ceil() -> SelfCompute the numerical ceiling.
method
src.narwhals.series.Series.clip(lower_bound:Self | NumericLiteral | TemporalLiteral | None=None, upper_bound:Self | NumericLiteral | TemporalLiteral | None=None) -> SelfClip values in the Series.
method
src.narwhals.series.Series.cos() -> SelfCompute the element-wise value for the cosine.
method
src.narwhals.series.Series.count() -> intReturns the number of non-null elements in the Series.
method
src.narwhals.series.Series.cum_count(*reverse:bool=False) -> SelfReturn the cumulative count of the non-null values in the series.
method
src.narwhals.series.Series.cum_max(*reverse:bool=False) -> SelfReturn the cumulative max of the non-null values in the series.
method
src.narwhals.series.Series.cum_min(*reverse:bool=False) -> SelfReturn the cumulative min of the non-null values in the series.
method
src.narwhals.series.Series.cum_sum(*reverse:bool=False) -> SelfCalculate the cumulative sum.
method
src.narwhals.series.Series.drop_nulls() -> SelfDrop null values.
method
src.narwhals.series.Series.dtype() -> DTypeGet the data type of the Series.
method
src.narwhals.series.Series.exp() -> SelfCompute the exponent.
method
src.narwhals.series.Series.fill_nan(value:float | None) -> SelfFill floating point NaN values with given value.
method
src.narwhals.series.Series.fill_null(value:Self | NonNestedLiteral=None, strategy:FillNullStrategy | None=None, limit:int | None=None) -> SelfFill null values using the specified value.
method
src.narwhals.series.Series.filter(predicate:Any) -> SelfFilter elements in the Series based on a condition.
method
src.narwhals.series.Series.first() -> PythonLiteralGet the first element of the Series.
method
src.narwhals.series.Series.floor() -> SelfCompute the numerical floor.
method
src.narwhals.series.Series.from_iterable(name:str, values:Iterable[Any], dtype:IntoDType | None=None, *backend:IntoBackend[EagerAllowed | PluginName]) -> Series[Any]Construct a Series from an iterable.
method
src.narwhals.series.Series.from_numpy(name:str, values:_1DArray, dtype:IntoDType | None=None, *backend:IntoBackend[EagerAllowed | PluginName]) -> Series[Any]Construct a Series from a NumPy ndarray.
method
src.narwhals.series.Series.gather_every(n:int, offset:int=0) -> SelfTake every nth value in the Series and return as new Series.
method
src.narwhals.series.Series.head(n:int=10) -> SelfGet the first `n` rows.
method
src.narwhals.series.Series.is_duplicated() -> SelfGet a mask of all duplicated rows in the Series.
method
src.narwhals.series.Series.is_empty() -> boolCheck if the series is empty.
method
src.narwhals.series.Series.is_in(other:Any) -> SelfCheck if the elements of this Series are in the other sequence.
method
src.narwhals.series.Series.is_nan() -> SelfReturns a boolean Series indicating which values are NaN.
method
src.narwhals.series.Series.is_null() -> SelfReturns a boolean Series indicating which values are null.
method
src.narwhals.series.Series.is_sorted(*descending:bool=False) -> boolCheck if the Series is sorted.
method
src.narwhals.series.Series.is_unique() -> SelfGet a mask of all unique rows in the Series.
method
src.narwhals.series.Series.last() -> PythonLiteralGet the last element of the Series.
method
src.narwhals.series.Series.len() -> intReturn the number of elements in the Series.
method
src.narwhals.series.Series.log(base:float=math.e) -> SelfCompute the logarithm to a given base.
method
src.narwhals.series.Series.max() -> AnyGet the maximum value in this Series.
method
src.narwhals.series.Series.mean() -> floatReduce this Series to the mean value.
method
src.narwhals.series.Series.median() -> floatReduce this Series to the median value.
method
src.narwhals.series.Series.min() -> AnyGet the minimal value in this Series.
method
src.narwhals.series.Series.n_unique() -> intCount the number of unique values.
method
src.narwhals.series.Series.name() -> strGet the name of the Series.
method
src.narwhals.series.Series.null_count() -> intCount the number of null values.
method
src.narwhals.series.Series.pipe(function:Callable[[Any], Self], *args:Any, **kwargs:Any) -> SelfPipe function call.
method
src.narwhals.series.Series.quantile(quantile:float, interpolation:RollingInterpolationMethod) -> floatGet quantile value of the series.
method
src.narwhals.series.Series.rank(method:RankMethod='average', *descending:bool=False) -> SelfAssign ranks to data, dealing with ties appropriately.
method
src.narwhals.series.Series.rename(name:str) -> SelfRename the Series.
method
src.narwhals.series.Series.rolling_mean(window_size:int, *min_samples:int | None=None, *center:bool=False) -> SelfApply a rolling mean (moving mean) over the values.
method
src.narwhals.series.Series.rolling_sum(window_size:int, *min_samples:int | None=None, *center:bool=False) -> SelfApply a rolling sum (moving sum) over the values.
method
src.narwhals.series.Series.round(decimals:int=0) -> SelfRound underlying floating point data by `decimals` digits.
method
src.narwhals.series.Series.sample(n:int | None=None, *fraction:float | None=None, *with_replacement:bool=False, *seed:int | None=None) -> SelfSample randomly from this Series.
method
src.narwhals.series.Series.scatter(indices:Self | Iterable[int] | int, values:Self | Iterable[PythonLiteral] | PythonLiteral) -> SelfSet value(s) at the given index location(s).
method
src.narwhals.series.Series.shape() -> tuple[int]Get the shape of the Series.
method
src.narwhals.series.Series.shift(n:int) -> SelfShift values by `n` positions.
method
src.narwhals.series.Series.sin() -> SelfCompute the element-wise value for the sine.
method
src.narwhals.series.Series.skew() -> float | NoneCalculate the sample skewness of the Series.
method
src.narwhals.series.Series.sort(*descending:bool=False, *nulls_last:bool=False) -> SelfSort this Series.
method
src.narwhals.series.Series.sqrt() -> SelfCompute the square root.
method
src.narwhals.series.Series.std(*ddof:int=1) -> floatGet the standard deviation of this Series.
method
src.narwhals.series.Series.sum() -> floatReduce this Series to the sum value.
method
src.narwhals.series.Series.tail(n:int=10) -> SelfGet the last `n` rows.
method
src.narwhals.series.Series.to_arrow() -> pa.Array[Any]Convert to arrow.
method
src.narwhals.series.Series.to_dummies(*separator:str='_', *drop_first:bool=False) -> DataFrame[Any]Get dummy/indicator variables.
method
src.narwhals.series.Series.to_frame() -> DataFrame[Any]Convert to dataframe.
method
src.narwhals.series.Series.to_list() -> list[Any]Convert to list.
method
src.narwhals.series.Series.to_native() -> IntoSeriesTConvert Narwhals series to native series.
method
src.narwhals.series.Series.to_numpy() -> _1DArrayConvert to numpy.
method
src.narwhals.series.Series.to_pandas() -> pd.Series[Any]Convert to pandas Series.
method
src.narwhals.series.Series.to_polars() -> pl.SeriesConvert to polars Series.
method
src.narwhals.series.Series.unique(*maintain_order:bool=False) -> SelfReturns unique values of the series.
method
src.narwhals.series.Series.value_counts(*sort:bool=False, *parallel:bool=False, *name:str | None=None, *normalize:bool=False) -> DataFrame[Any]Count the occurrences of unique values.
method
src.narwhals.series.Series.var(*ddof:int=1) -> floatGet the variance of this Series.
method
src.narwhals.series.Series.zip_with(mask:Self, other:Self) -> SelfTake values from self or other based on the given mask.
class
src.narwhals.sql.SQLTableA LazyFrame with an additional `to_sql` method.
method
src.narwhals.sql.SQLTable.to_sql(*pretty:bool=False) -> strConvert to SQL query.
func
src.narwhals.sql.table(name:str, schema:IntoSchema) -> SQLTableGenerate standalone LazyFrame which you can use to generate SQL.
method
src.narwhals.stable.v1.Expr.arg_max() -> SelfReturns the index of the maximum value.
method
src.narwhals.stable.v1.Expr.arg_min() -> SelfReturns the index of the minimum value.
method
src.narwhals.stable.v1.Expr.arg_true() -> SelfFind elements where boolean expression is True.
method
src.narwhals.stable.v1.Expr.first() -> SelfGet the first value.
method
src.narwhals.stable.v1.Expr.gather_every(n:int, offset:int=0) -> SelfTake every nth value in the Series and return as new Series.
method
src.narwhals.stable.v1.Expr.head(n:int=10) -> SelfGet the first `n` rows.
method
src.narwhals.stable.v1.Expr.last() -> SelfGet the last value.
method
src.narwhals.stable.v1.Expr.sample(n:int | None=None, *fraction:float | None=None, *with_replacement:bool=False, *seed:int | None=None) -> SelfSample randomly from this expression.
method
src.narwhals.stable.v1.Expr.sort(*descending:bool=False, *nulls_last:bool=False) -> SelfSort this column.
method
src.narwhals.stable.v1.Expr.tail(n:int=10) -> SelfGet the last `n` rows.
method
src.narwhals.stable.v1.Expr.unique(*maintain_order:bool | None=None) -> SelfReturn unique values of this expression.
method
src.narwhals.stable.v1.LazyFrame.tail(n:int=5) -> SelfGet the last `n` rows.
class
src.narwhals.stable.v1._dtypes.EnumA fixed categorical encoding of a unique set of strings.
func
src.narwhals.stable.v1.cov(a:IntoExpr, b:IntoExpr, *ddof:int=1) -> ExprCompute the covariance between two columns.
func
src.narwhals.stable.v1.format(f_string:str, *args:IntoExpr) -> ExprFormat expressions as a string.
func
src.narwhals.stable.v1.read_csv(source:FileSource, *backend:IntoBackend[EagerAllowed | PluginName] | None=None, *native_namespace:ModuleType | None=None, **kwargs:Any) -> DataFrame[Any]Read a CSV file into a DataFrame.
func
src.narwhals.stable.v1.scan_csv(source:FileSource, *backend:IntoBackend[Backend | PluginName] | None=None, *native_namespace:ModuleType | None=None, **kwargs:Any) -> LazyFrame[Any]Lazily read from a CSV file.
func
src.narwhals.stable.v1.scan_parquet(source:FileSource, *backend:IntoBackend[Backend | PluginName] | None=None, *native_namespace:ModuleType | None=None, **kwargs:Any) -> LazyFrame[Any]Lazily read from a parquet file.
func
src.narwhals.stable.v1.struct(*exprs:IntoExpr | Sequence[IntoExpr], **named_exprs:IntoExpr) -> ExprCollect columns into a struct column.
method
src.narwhals.stable.v2.Expr.first() -> SelfGet the first value.
method
src.narwhals.stable.v2.Expr.last() -> SelfGet the last value.
func
src.narwhals.stable.v2.all() -> ExprInstantiate an expression representing all columns.
func
src.narwhals.stable.v2.all_horizontal(*ignore_nulls:bool, *exprs:IntoExpr | Iterable[IntoExpr]) -> ExprCompute the bitwise AND horizontally across columns.
func
src.narwhals.stable.v2.any_horizontal(*ignore_nulls:bool, *exprs:IntoExpr | Iterable[IntoExpr]) -> ExprCompute the bitwise OR horizontally across columns.
func
src.narwhals.stable.v2.cov(a:IntoExpr, b:IntoExpr, *ddof:int=1) -> ExprCompute the covariance between two columns.
func
src.narwhals.stable.v2.exclude(*names:str | Iterable[str]) -> ExprCreates an expression that excludes columns by their name(s).
func
src.narwhals.stable.v2.format(f_string:str, *args:IntoExpr) -> ExprFormat expressions as a string.
func
src.narwhals.stable.v2.len() -> ExprReturn the number of rows.
func
src.narwhals.stable.v2.lit(value:NonNestedLiteral, dtype:IntoDType | None=None) -> ExprReturn an expression representing a literal value.
func
src.narwhals.stable.v2.max(*columns:str) -> ExprReturn the maximum value.
func
src.narwhals.stable.v2.max_horizontal(*exprs:IntoExpr | Iterable[IntoExpr]) -> ExprGet the maximum value horizontally across columns.
func
src.narwhals.stable.v2.mean(*columns:str) -> ExprGet the mean value.
func
src.narwhals.stable.v2.mean_horizontal(*exprs:IntoExpr | Iterable[IntoExpr]) -> ExprCompute the mean of all values horizontally across columns.
func
src.narwhals.stable.v2.median(*columns:str) -> ExprGet the median value.
func
src.narwhals.stable.v2.min(*columns:str) -> ExprReturn the minimum value.
func
src.narwhals.stable.v2.min_horizontal(*exprs:IntoExpr | Iterable[IntoExpr]) -> ExprGet the minimum value horizontally across columns.
func
src.narwhals.stable.v2.new_series(name:str, values:Any, dtype:IntoDType | None=None, *backend:IntoBackend[EagerAllowed | PluginName]) -> Series[Any]Instantiate Narwhals Series from iterable (e.g.
func
src.narwhals.stable.v2.read_csv(source:str, *backend:IntoBackend[EagerAllowed | PluginName], *separator:str=',', **kwargs:Any) -> DataFrame[Any]Read a CSV file into a DataFrame.
func
src.narwhals.stable.v2.read_parquet(source:str, *backend:IntoBackend[EagerAllowed | PluginName], **kwargs:Any) -> DataFrame[Any]Read into a DataFrame from a parquet file.
func
src.narwhals.stable.v2.scan_csv(source:str, *backend:IntoBackend[Backend | PluginName], *separator:str=',', **kwargs:Any) -> LazyFrame[Any]Lazily read from a CSV file.
func
src.narwhals.stable.v2.scan_parquet(source:str, *backend:IntoBackend[Backend | PluginName], **kwargs:Any) -> LazyFrame[Any]Lazily read from a parquet file.
func
src.narwhals.stable.v2.struct(*exprs:IntoExpr | Sequence[IntoExpr], **named_exprs:IntoExpr) -> ExprCollect columns into a struct column.
func
src.narwhals.stable.v2.sum(*columns:str) -> ExprSum all values.
func
src.narwhals.stable.v2.sum_horizontal(*exprs:IntoExpr | Iterable[IntoExpr]) -> ExprSum all values horizontally across columns.
func
src.narwhals.stable.v2.when(*predicates:IntoExpr | Iterable[IntoExpr]) -> WhenStart a `when-then-otherwise` expression.
func
src.narwhals.translate.get_native_namespace(*obj:Frame | Series[Any] | IntoFrame | IntoSeries) -> AnyGet native namespace from object.
func
src.narwhals.translate.to_py_scalar(scalar_like:Any) -> AnyIf a scalar is not Python native, converts it to Python native.
method
tpch.classes.Query.inputs(backend:Backend) -> tuple[nw.LazyFrame[Any], ...]Get the frame inputs for this query at the given scale factor.
class
tpch.classes.TableLoggerA logger that streams table rows with box-drawing characters.
method
tpch.classes.TableLogger.format_size(n_bytes:float) -> strReturn the best human-readable size and unit for the given byte count.
func
utils.check_dist_content.git_tracked(*pathspecs:str) -> set[str]Return the set of git-tracked files under the given pathspecs.
func
utils.check_docstrings.cleanup_temp_files(temp_files:list[tuple[Path, str]]) -> NoneRemove all temporary files.
func
utils.check_docstrings.extract_docstring_examples(files:list[str]) -> list[tuple[Path, str, str]]Extract examples from docstrings in Python files.
func
utils.check_docstrings.find_ruff_bin() -> PathReturn the ruff binary path.
func
utils.check_docstrings.report_errors(completed:CompletedProcess[str] | None, temp_files:list[tuple[Path, str]]) -> NoneMap errors back to original examples and report them.
method
utils.generate_backend_completeness.Backend.is_eager_allowed() -> boolCheck if a backend supports eager evaluation.
func
utils.generate_backend_completeness.generate_completeness_tables() -> NoneGenerate all backend completeness tables.
func
utils.generate_backend_completeness.get_narwhals_methods(module_name:str, class_name:str) -> set[str]Get all public methods from a narwhals top-level class.
func
utils.generate_backend_completeness.render_table_and_write_to_output(df:pl.DataFrame, title:str, output_filename:str) -> NoneRender a markdown table and write it to a file.
func
utils.sort_api_reference.sort_list(match:re.Match[str]) -> strSort a matched members list section.
func
utils.sort_api_reference.sort_members_in_markdown(file_path:Path) -> intSort members lists in a markdown file alphabetically.
About this data
These signatures were extracted from the public source of narwhals-dev/narwhals
using Python's ast module. Argument names, default values,
type annotations and return types are taken verbatim from the code.
Implementation bodies are never stored. See
how it works for details.