5
5
from .errors import PinsInsecureReadError
6
6
7
7
from typing import Literal , Sequence
8
- from typing_extensions import assert_never
9
8
10
9
# TODO: move IFileSystem out of boards, to fix circular import
11
10
# from .boards import IFileSystem
@@ -24,7 +23,8 @@ def _assert_is_pandas_df(x, file_type: str) -> None:
24
23
)
25
24
26
25
27
- def _get_df_family (df ) -> Literal ["unknown" , "pandas" , "polars" ]:
26
+ def _get_df_family (df ) -> Literal ["pandas" , "polars" ]:
27
+ """Return the type of DataFrame, or raise NotImplementedError if we can't decide."""
28
28
try :
29
29
import polars as pl
30
30
except ModuleNotFoundError :
@@ -36,16 +36,15 @@ def _get_df_family(df) -> Literal["unknown", "pandas", "polars"]:
36
36
37
37
is_pandas_df = isinstance (df , pd .DataFrame )
38
38
39
- if not is_polars_df and not is_pandas_df :
40
- return "unknown"
41
- if is_polars_df and is_pandas_df : # Hybrid DataFrame type!
42
- return "unknown"
39
+ if is_polars_df and is_pandas_df :
40
+ raise NotImplementedError (
41
+ " Hybrid DataFrames (simultaneously pandas and polars) are not supported."
42
+ )
43
43
elif is_polars_df :
44
44
return "polars"
45
45
elif is_pandas_df :
46
46
return "pandas"
47
- else :
48
- assert_never (df )
47
+ raise NotImplementedError (f"Unrecognized DataFrame type: { type (df )} " )
49
48
50
49
51
50
def load_path (meta , path_to_version ):
@@ -234,15 +233,13 @@ def save_data(obj, fname, type=None, apply_suffix: bool = True) -> "str | Sequen
234
233
235
234
236
235
def default_title (obj , name ):
237
- df_family = _get_df_family (obj )
238
-
239
- if df_family in ("pandas" , "polars" ):
240
- # TODO(compat): title says CSV rather than data.frame
241
- # see https://github.com/machow/pins-python/issues/5
242
- shape_str = " x " .join (map (str , obj .shape ))
243
- return f"{ name } : a pinned { shape_str } DataFrame"
244
- elif df_family == "unknown" :
236
+ try :
237
+ _get_df_family (obj )
238
+ except NotImplementedError :
245
239
obj_name = type (obj ).__qualname__
246
240
return f"{ name } : a pinned { obj_name } object"
247
- else :
248
- assert_never (df_family )
241
+
242
+ # TODO(compat): title says CSV rather than data.frame
243
+ # see https://github.com/machow/pins-python/issues/5
244
+ shape_str = " x " .join (map (str , obj .shape ))
245
+ return f"{ name } : a pinned { shape_str } DataFrame"
0 commit comments