Skip to content

Commit 8e5cc66

Browse files
authored
fix pyarrow to_date (#1216)
1 parent 90836bd commit 8e5cc66

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

narwhals/_arrow/series.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ def date(self: Self) -> ArrowSeries:
784784
import pyarrow as pa # ignore-banned-import()
785785

786786
return self._arrow_series._from_native_series(
787-
self._arrow_series._native_series.cast(pa.date64())
787+
self._arrow_series._native_series.cast(pa.date32())
788788
)
789789

790790
def year(self: Self) -> ArrowSeries:

tests/expr_and_series/dt/datetime_attributes_test.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,15 @@ def test_datetime_chained_attributes(
104104

105105
result = df.select(nw.col("a").dt.date().dt.year())
106106
compare_dicts(result, {"a": [2021, 2020]})
107+
108+
109+
def test_to_date(request: pytest.FixtureRequest, constructor: Constructor) -> None:
110+
if any(
111+
x in str(constructor)
112+
for x in ("pandas_constructor", "pandas_nullable_constructor", "dask")
113+
):
114+
request.applymarker(pytest.mark.xfail)
115+
dates = {"a": [datetime(2001, 1, 1), None, datetime(2001, 1, 3)]}
116+
df = nw.from_native(constructor(dates))
117+
result = df.select(nw.col("a").dt.date())
118+
assert result.collect_schema() == {"a": nw.Date}

0 commit comments

Comments
 (0)