diff options
| author | sotech117 <michael_foiani@brown.edu> | 2025-07-31 17:27:24 -0400 |
|---|---|---|
| committer | sotech117 <michael_foiani@brown.edu> | 2025-07-31 17:27:24 -0400 |
| commit | 5bf22fc7e3c392c8bd44315ca2d06d7dca7d084e (patch) | |
| tree | 8dacb0f195df1c0788d36dd0064f6bbaa3143ede /venv/lib/python3.8/site-packages/narwhals/_interchange/series.py | |
| parent | b832d364da8c2efe09e3f75828caf73c50d01ce3 (diff) | |
add code for analysis of data
Diffstat (limited to 'venv/lib/python3.8/site-packages/narwhals/_interchange/series.py')
| -rw-r--r-- | venv/lib/python3.8/site-packages/narwhals/_interchange/series.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/venv/lib/python3.8/site-packages/narwhals/_interchange/series.py b/venv/lib/python3.8/site-packages/narwhals/_interchange/series.py new file mode 100644 index 0000000..67f062b --- /dev/null +++ b/venv/lib/python3.8/site-packages/narwhals/_interchange/series.py @@ -0,0 +1,47 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, NoReturn + +from narwhals._interchange.dataframe import map_interchange_dtype_to_narwhals_dtype +from narwhals._utils import Version + +if TYPE_CHECKING: + from typing_extensions import Self + + from narwhals.dtypes import DType + + +class InterchangeSeries: + _version = Version.V1 + + def __init__(self, df: Any) -> None: + self._native_series = df + + def __narwhals_series__(self) -> Self: + return self + + def __native_namespace__(self) -> NoReturn: + msg = ( + "Cannot access native namespace for interchange-level series with unknown backend. " + "If you would like to see this kind of object supported in Narwhals, please " + "open a feature request at https://github.com/narwhals-dev/narwhals/issues." + ) + raise NotImplementedError(msg) + + @property + def dtype(self) -> DType: + return map_interchange_dtype_to_narwhals_dtype(self._native_series.dtype) + + @property + def native(self) -> Any: + return self._native_series + + def __getattr__(self, attr: str) -> NoReturn: + msg = ( # pragma: no cover + f"Attribute {attr} is not supported for interchange-level dataframes.\n\n" + "Hint: you probably called `nw.from_native` on an object which isn't fully " + "supported by Narwhals, yet implements `__dataframe__`. If you would like to " + "see this kind of object supported in Narwhals, please open a feature request " + "at https://github.com/narwhals-dev/narwhals/issues." + ) + raise NotImplementedError(msg) |
