Skip to content

Commit

Permalink
docs: add Enum dtype docstring example (#1514)
Browse files Browse the repository at this point in the history
* Add docstring example for converting pl.Enum to nw.Enum

* Pandas and PyArrow don't have Enum dtypes, so no example given.
* Tried giving a Narwhals example of category validation using `nw.replace_strict` and having `return_dtype=nw.Enum()` but casting to Enum is not supported and `nw.Enum` accepts no allowed categories anyway.

* Use same `data` as Categorical and String examples

* Remove unused imports
  • Loading branch information
chrisschopp authored Dec 5, 2024
1 parent 638a176 commit 226fc9c
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion narwhals/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,19 @@ class Categorical(DType):


class Enum(DType):
"""A fixed categorical encoding of a unique set of strings."""
"""A fixed categorical encoding of a unique set of strings.
Polars has an Enum data type, while pandas and PyArrow do not.
Examples:
>>> import polars as pl
>>> import narwhals as nw
>>> data = ["beluga", "narwhal", "orca", "vaquita"]
>>> ser_pl = pl.Series(data, dtype=pl.Enum(data))
>>> nw.from_native(ser_pl, series_only=True).dtype
Enum
"""


class Field:
Expand Down

0 comments on commit 226fc9c

Please sign in to comment.