From 64a40938de001ea57e8384bccd46ea0d24bc4b05 Mon Sep 17 00:00:00 2001 From: Marco Gorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Sun, 17 Mar 2024 15:17:09 +0000 Subject: [PATCH] extending --- docs/extending.md | 2 ++ mkdocs.yml | 1 + narwhals/dataframe.py | 3 +++ 3 files changed, 6 insertions(+) create mode 100644 docs/extending.md diff --git a/docs/extending.md b/docs/extending.md new file mode 100644 index 000000000..f398cd864 --- /dev/null +++ b/docs/extending.md @@ -0,0 +1,2 @@ +# How Narwhals can support your dataframe as well! + diff --git a/mkdocs.yml b/mkdocs.yml index 064c8fe5b..ae63173b0 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -8,6 +8,7 @@ nav: - basics/dataframe.md - basics/column.md - basics/complete_example.md + - Extending: extending.md - API Reference: reference.md theme: name: material diff --git a/narwhals/dataframe.py b/narwhals/dataframe.py index 625f8c83d..ef00cb134 100644 --- a/narwhals/dataframe.py +++ b/narwhals/dataframe.py @@ -177,6 +177,9 @@ def __init__( ): # pragma: no cover self._dataframe = PandasDataFrame(df, implementation="cudf") self._implementation = "cudf" + elif hasattr(df, "__narwhals_dataframe__"): + self._dataframe = df.__narwhals_dataframe__() + self._implementation = "custom" else: msg = f"Expected pandas-like dataframe, Polars dataframe, or Polars lazyframe, got: {type(df)}" raise TypeError(msg)