1919)
2020
2121import narwhals .stable .v1 as nw
22- from narwhals .dependencies import is_pandas_dataframe as _is_pandas_dataframe
23- from narwhals .typing import IntoDataFrame
22+ from narwhals .stable .v1 .typing import IntoDataFrame
2423
2524from ._importers import import_pyarrow_interchange
2625from .core import (
@@ -76,7 +75,7 @@ class SupportsGeoInterface(Protocol):
7675
7776def is_data_type (obj : Any ) -> TypeIs [DataType ]:
7877 return isinstance (obj , (dict , SupportsGeoInterface )) or isinstance (
79- nw .from_native (obj , eager_or_interchange_only = True , strict = False ),
78+ nw .from_native (obj , eager_or_interchange_only = True , pass_through = True ),
8079 nw .DataFrame ,
8180 )
8281
@@ -188,7 +187,7 @@ def sample(
188187 if data is None :
189188 return partial (sample , n = n , frac = frac )
190189 check_data_type (data )
191- if _is_pandas_dataframe (data ):
190+ if nw . dependencies . is_pandas_dataframe (data ):
192191 return data .sample (n = n , frac = frac )
193192 elif isinstance (data , dict ):
194193 if "values" in data :
@@ -210,7 +209,7 @@ def sample(
210209 raise ValueError (msg )
211210 n = int (frac * len (data ))
212211 indices = random .sample (range (len (data )), n )
213- return nw . to_native ( data [indices ])
212+ return data [indices ]. to_native ( )
214213
215214
216215_FormatType = Literal ["csv" , "json" ]
@@ -319,11 +318,11 @@ def _to_text_kwds(prefix: str, extension: str, filename: str, urlpath: str, /) -
319318def to_values (data : DataType ) -> ToValuesReturnType :
320319 """Replace a DataFrame by a data model with values."""
321320 check_data_type (data )
322- # `strict=False ` passes `data` through as-is if it is not a Narwhals object.
323- data_native = nw .to_native (data , strict = False )
321+ # `pass_through=True ` passes `data` through as-is if it is not a Narwhals object.
322+ data_native = nw .to_native (data , pass_through = True )
324323 if isinstance (data_native , SupportsGeoInterface ):
325324 return {"values" : _from_geo_interface (data_native )}
326- elif _is_pandas_dataframe (data_native ):
325+ elif nw . dependencies . is_pandas_dataframe (data_native ):
327326 data_native = sanitize_pandas_dataframe (data_native )
328327 return {"values" : data_native .to_dict (orient = "records" )}
329328 elif isinstance (data_native , dict ):
@@ -364,7 +363,7 @@ def _from_geo_interface(data: SupportsGeoInterface | Any) -> dict[str, Any]:
364363 - ``typing.TypeGuard``
365364 - ``pd.DataFrame.__getattr__``
366365 """
367- if _is_pandas_dataframe (data ):
366+ if nw . dependencies . is_pandas_dataframe (data ):
368367 data = sanitize_pandas_dataframe (data )
369368 return sanitize_geo_interface (data .__geo_interface__ )
370369
@@ -374,7 +373,7 @@ def _data_to_json_string(data: DataType) -> str:
374373 check_data_type (data )
375374 if isinstance (data , SupportsGeoInterface ):
376375 return json .dumps (_from_geo_interface (data ))
377- elif _is_pandas_dataframe (data ):
376+ elif nw . dependencies . is_pandas_dataframe (data ):
378377 data = sanitize_pandas_dataframe (data )
379378 return data .to_json (orient = "records" , double_precision = 15 )
380379 elif isinstance (data , dict ):
@@ -401,7 +400,7 @@ def _data_to_csv_string(data: DataType) -> str:
401400 f"See https://github.com/vega/altair/issues/3441"
402401 )
403402 raise NotImplementedError (msg )
404- elif _is_pandas_dataframe (data ):
403+ elif nw . dependencies . is_pandas_dataframe (data ):
405404 data = sanitize_pandas_dataframe (data )
406405 return data .to_csv (index = False )
407406 elif isinstance (data , dict ):
0 commit comments