Skip to content

narwhals.dependencies

get_cudf() -> Any

Get cudf module (if already imported - else return None).

get_ibis() -> Any

Get ibis module (if already imported - else return None).

get_modin() -> Any

Get modin.pandas module (if already imported - else return None).

get_pandas() -> Any

Get pandas module (if already imported - else return None).

get_polars() -> Any

Get Polars module (if already imported - else return None).

get_pyarrow() -> Any

Get pyarrow module (if already imported - else return None).

is_cudf_dataframe(df: Any) -> TypeGuard[cudf.DataFrame]

Check whether df is a cudf DataFrame without importing cudf.

is_cudf_index(index: Any) -> TypeGuard[cudf.Index]

Check whether index is a cudf Index without importing cudf.

is_cudf_series(ser: Any) -> TypeGuard[cudf.Series[Any]]

Check whether ser is a cudf Series without importing cudf.

is_dask_dataframe(df: Any) -> TypeGuard[dd.DataFrame]

Check whether df is a Dask DataFrame without importing Dask.

is_ibis_table(df: Any) -> TypeGuard[ibis.Table]

Check whether df is a Ibis Table without importing Ibis.

is_into_dataframe(native_dataframe: Any) -> bool

Check whether native_dataframe can be converted to a Narwhals DataFrame.

Parameters:

Name Type Description Default
native_dataframe Any

The object to check.

required

Returns:

Type Description
bool

True if native_dataframe can be converted to a Narwhals DataFrame, False otherwise.

Examples:

>>> import pandas as pd
>>> import polars as pl
>>> import numpy as np
>>> from narwhals.dependencies import is_into_dataframe
>>> df_pd = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
>>> df_pl = pl.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
>>> np_arr = np.array([[1, 4], [2, 5], [3, 6]])
>>> is_into_dataframe(df_pd)
True
>>> is_into_dataframe(df_pl)
True
>>> is_into_dataframe(np_arr)
False

is_into_series(native_series: IntoSeries) -> bool

Check whether native_series can be converted to a Narwhals Series.

Parameters:

Name Type Description Default
native_series IntoSeries

The object to check.

required

Returns:

Type Description
bool

True if native_series can be converted to a Narwhals Series, False otherwise.

Examples:

>>> import pandas as pd
>>> import polars as pl
>>> import numpy as np
>>> import narwhals as nw
>>> s_pd = pd.Series([1, 2, 3])
>>> s_pl = pl.Series([1, 2, 3])
>>> np_arr = np.array([1, 2, 3])
>>> nw.dependencies.is_into_series(s_pd)
True
>>> nw.dependencies.is_into_series(s_pl)
True
>>> nw.dependencies.is_into_series(np_arr)
False

is_modin_dataframe(df: Any) -> TypeGuard[mpd.DataFrame]

Check whether df is a modin DataFrame without importing modin.

is_modin_index(index: Any) -> TypeGuard[mpd.Index]

Check whether index is a modin Index without importing modin.

is_modin_series(ser: Any) -> TypeGuard[mpd.Series]

Check whether ser is a modin Series without importing modin.

is_numpy_array(arr: Any) -> TypeGuard[np.ndarray]

Check whether arr is a NumPy Array without importing NumPy.

is_pandas_dataframe(df: Any) -> TypeGuard[pd.DataFrame]

Check whether df is a pandas DataFrame without importing pandas.

is_pandas_index(index: Any) -> TypeGuard[pd.Index]

Check whether index is a pandas Index without importing pandas.

is_pandas_like_dataframe(df: Any) -> bool

Check whether df is a pandas-like DataFrame without doing any imports.

By "pandas-like", we mean: pandas, Modin, cuDF.

is_pandas_like_index(index: Any) -> bool

Check whether index is a pandas-like Index without doing any imports.

By "pandas-like", we mean: pandas, Modin, cuDF.

is_pandas_like_series(ser: Any) -> bool

Check whether ser is a pandas-like Series without doing any imports.

By "pandas-like", we mean: pandas, Modin, cuDF.

is_pandas_series(ser: Any) -> TypeGuard[pd.Series[Any]]

Check whether ser is a pandas Series without importing pandas.

is_polars_dataframe(df: Any) -> TypeGuard[pl.DataFrame]

Check whether df is a Polars DataFrame without importing Polars.

is_polars_lazyframe(df: Any) -> TypeGuard[pl.LazyFrame]

Check whether df is a Polars LazyFrame without importing Polars.

is_polars_series(ser: Any) -> TypeGuard[pl.Series]

Check whether ser is a Polars Series without importing Polars.

is_pyarrow_chunked_array(ser: Any) -> TypeGuard[pa.ChunkedArray]

Check whether ser is a PyArrow ChunkedArray without importing PyArrow.

is_pyarrow_table(df: Any) -> TypeGuard[pa.Table]

Check whether df is a PyArrow Table without importing PyArrow.