aboutsummaryrefslogtreecommitdiff
path: root/venv/lib/python3.8/site-packages/narwhals/series_cat.py
diff options
context:
space:
mode:
Diffstat (limited to 'venv/lib/python3.8/site-packages/narwhals/series_cat.py')
-rw-r--r--venv/lib/python3.8/site-packages/narwhals/series_cat.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/venv/lib/python3.8/site-packages/narwhals/series_cat.py b/venv/lib/python3.8/site-packages/narwhals/series_cat.py
new file mode 100644
index 0000000..cb976d4
--- /dev/null
+++ b/venv/lib/python3.8/site-packages/narwhals/series_cat.py
@@ -0,0 +1,30 @@
+from __future__ import annotations
+
+from typing import Generic
+
+from narwhals.typing import SeriesT
+
+
+class SeriesCatNamespace(Generic[SeriesT]):
+ def __init__(self, series: SeriesT) -> None:
+ self._narwhals_series = series
+
+ def get_categories(self) -> SeriesT:
+ """Get unique categories from column.
+
+ Returns:
+ A new Series containing the unique categories.
+
+ Examples:
+ >>> import pandas as pd
+ >>> import narwhals as nw
+ >>> s_native = pd.Series(["apple", "mango", "mango"], dtype="category")
+ >>> s = nw.from_native(s_native, series_only=True)
+ >>> s.cat.get_categories().to_native()
+ 0 apple
+ 1 mango
+ dtype: object
+ """
+ return self._narwhals_series._with_compliant(
+ self._narwhals_series._compliant_series.cat.get_categories()
+ )