diff --git a/narwhals/dataframe.py b/narwhals/dataframe.py index 6b673a806..81bdee55e 100644 --- a/narwhals/dataframe.py +++ b/narwhals/dataframe.py @@ -72,9 +72,7 @@ def __narwhals_namespace__(self: Self) -> Any: def _from_compliant_dataframe(self: Self, df: Any) -> Self: # construct, preserving properties - return self.__class__( # type: ignore[call-arg] - df, level=self._level - ) + return self.__class__(df, level=self._level) # type: ignore[call-arg] def _flatten_and_extract( self, *exprs: IntoExpr | Iterable[IntoExpr], **named_exprs: IntoExpr diff --git a/narwhals/functions.py b/narwhals/functions.py index 0d0a1e29c..e66b46bdf 100644 --- a/narwhals/functions.py +++ b/narwhals/functions.py @@ -41,10 +41,12 @@ from types import ModuleType import numpy as np + import pyarrow as pa from typing_extensions import Self from narwhals.dtypes import DType from narwhals.series import Series + from narwhals.typing import DTypeBackend from narwhals.typing import IntoDataFrameT from narwhals.typing import IntoExpr from narwhals.typing import IntoFrameT @@ -351,13 +353,14 @@ def _new_series_impl( native_series = native_namespace.Series(values, name=name) elif implementation is Implementation.PYARROW: + pa_dtype: pa.DataType | None = None if dtype: from narwhals._arrow.utils import ( narwhals_to_native_dtype as arrow_narwhals_to_native_dtype, ) - dtype = arrow_narwhals_to_native_dtype(dtype, version=version) - native_series = native_namespace.chunked_array([values], type=dtype) + pa_dtype = arrow_narwhals_to_native_dtype(dtype, version=version) + native_series = native_namespace.chunked_array([values], type=pa_dtype) elif implementation is Implementation.DASK: # pragma: no cover msg = "Dask support in Narwhals is lazy-only, so `new_series` is not supported" @@ -521,10 +524,11 @@ def _from_dict_impl( if schema: from narwhals._pandas_like.utils import get_dtype_backend - pd_schema = Schema(schema).to_pandas( + it: Iterable[DTypeBackend] = ( get_dtype_backend(native_type, eager_backend) for native_type in native_frame.dtypes ) + pd_schema = Schema(schema).to_pandas(it) native_frame = native_frame.astype(pd_schema) elif eager_backend is Implementation.PYARROW: diff --git a/narwhals/series.py b/narwhals/series.py index b33fc7a39..7dc251615 100644 --- a/narwhals/series.py +++ b/narwhals/series.py @@ -222,7 +222,7 @@ def __arrow_c_stream__(self: Self, requested_schema: object | None = None) -> ob if parse_version(pa.__version__) < (16, 0): # pragma: no cover msg = f"PyArrow>=16.0.0 is required for `Series.__arrow_c_stream__` for object of type {type(native_series)}" raise ModuleNotFoundError(msg) - ca = pa.chunked_array([self.to_arrow()]) + ca = pa.chunked_array([self.to_arrow()]) # type: ignore[call-overload, unused-ignore] return ca.__arrow_c_stream__(requested_schema=requested_schema) def to_native(self: Self) -> IntoSeriesT: