-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Pyarrow timestamp support for map() function #61236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 8 commits
0ce5571
469e28d
1dbf5d1
1cf2de8
52dc7fb
66215a9
4445ecd
49e130c
79c1fe2
91e6401
19d2870
88c180c
a421e66
04dda0d
02ae824
73c4039
b918323
f3545bf
4526bb1
52cd37f
25e57c3
c9f47ff
105d92b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1483,6 +1483,8 @@ def to_numpy( | |
def map(self, mapper, na_action: Literal["ignore"] | None = None): | ||
if is_numeric_dtype(self.dtype): | ||
return map_array(self.to_numpy(), mapper, na_action=na_action) | ||
elif self.dtype == "timestamp[ns][pyarrow]": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of adding an |
||
return map_array(self.to_numpy(dtype=object), mapper, na_action=na_action) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you avoid the type cast to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the failing test would need adjustment (we get a better result when we don't return |
||
else: | ||
return super().map(mapper, na_action) | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -604,3 +604,14 @@ def test_map_kwargs(): | |||||
result = Series([2, 4, 5]).map(lambda x, y: x + y, y=2) | ||||||
expected = Series([4, 6, 7]) | ||||||
tm.assert_series_equal(result, expected) | ||||||
|
||||||
|
||||||
def test_map_arrow_timestamp_dict(): | ||||||
# GH 61231 | ||||||
pytest.importorskip("pyarrow", minversion="10.0.1") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
ser = Series(date_range("2023-01-01", periods=3)).astype("timestamp[ns][pyarrow]") | ||||||
mapper = {ts: i for i, ts in enumerate(ser)} | ||||||
result = ser.map(mapper) | ||||||
expected = Series([0, 1, 2], dtype="int64") | ||||||
tm.assert_series_equal(result, expected) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead, this line should allow datelike types so
to_numpy
is called