GH-50464: [C++][Python] Simplify arrow_to_pandas DateOffset handling for nanoseconds/milliseconds#50465
Open
raulcd wants to merge 2 commits into
Open
GH-50464: [C++][Python] Simplify arrow_to_pandas DateOffset handling for nanoseconds/milliseconds#50465raulcd wants to merge 2 commits into
raulcd wants to merge 2 commits into
Conversation
…dling for nanoseconds/milliseconds
|
|
…Year, seconds, microseconds, minutes, hours, weeks
Member
Author
|
@jorisvandenbossche would there be any reason to keep roundtriping microseconds on |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR simplifies the Pandas DateOffset conversion path for month_day_nano_interval in arrow_to_pandas by no longer splitting nanoseconds into microseconds + remainder nanoseconds, and updates Python tests to expect nanoseconds-only roundtripping.
Changes:
- Simplify
MonthDayNanoIntervalType→ PandasDateOffsetconversion to passinterval.nanosecondsdirectly. - Update interval/dateoffset-related tests to assert nanoseconds-only behavior.
- Adjust expected
DateOffsetconstruction in tests to reflect the new output shape.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| python/pyarrow/src/arrow/python/arrow_to_pandas.cc | Removes microseconds/remainder splitting and passes total nanoseconds into DateOffset. |
| python/pyarrow/tests/test_pandas.py | Updates roundtrip expectations for DateOffset values produced from month-day-nano intervals. |
| python/pyarrow/tests/test_array.py | Updates DateOffset expectations in interval array tests to use nanoseconds-only representation. |
Comment on lines
1296
to
+1299
| PyDict_SetItemString(kwargs.obj(), "months", PyLong_FromLong(interval.months)); | ||
| PyDict_SetItemString(kwargs.obj(), "days", PyLong_FromLong(interval.days)); | ||
| PyDict_SetItemString(kwargs.obj(), "microseconds", | ||
| PyLong_FromLongLong(microseconds)); | ||
| PyDict_SetItemString(kwargs.obj(), "nanoseconds", PyLong_FromLongLong(nanoseconds)); | ||
| PyDict_SetItemString(kwargs.obj(), "nanoseconds", | ||
| PyLong_FromLongLong(interval.nanoseconds)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rationale for this change
Pandas 1.4 fixed the following:
Which made us special case microseconds extracting those from our
MonthDayNanoand manually buildingmicroseconds.DateOffsetcan be created with the following:We currently only roundtrip Month, Day, Microseconds and Nano due to our MonthDayNano data type. We special cased microseconds but we were not special casing years, seconds, minutos, hours or weeks.
As the initial issue that made us special case has been solved upstream we can stop roundtripping microseconds and just return nanoseconds simplifying our codebase.
What changes are included in this PR?
Remove the unnecessary code to retrieve microseconds from nanoseconds.
Update test as microseconds won't be returned, only nanoseconds.
Are these changes tested?
Yes via CI
Are there any user-facing changes?
Yes, this is a change of the UX.