Skip to content

Commit

Permalink
Merge branch 'main' into ci/validate-tpch-queries
Browse files Browse the repository at this point in the history
  • Loading branch information
FBruzzesi authored Feb 8, 2025
2 parents c2dd8c6 + 6ae40c9 commit 33e124b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
4 changes: 1 addition & 3 deletions narwhals/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions narwhals/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion narwhals/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 33e124b

Please sign in to comment.