Repository navigation
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Pickle round-trips for both new scalar classes raise ArrowNotImplementedError, including for nulls, because the reducer uses unsupported Python-value conversion.
1 open issue
What changed in this PR
Extends PyArrow’s interval support with month and day-time types, allowing existing compute functions to return typed Python arrays and scalars.
Changes:
- Adds public type factories, aliases, and interval classification.
- Adds array and scalar wrappers, with
as_py()returning month counts or(days, milliseconds)tuples. - Expands tests and API documentation.
| File | Description |
|---|---|
python/pyarrow/types.py |
Recognizes all three interval types. |
python/pyarrow/types.pxi |
Adds factories, aliases, and usage examples. |
python/pyarrow/tests/test_types.py |
Expands interval type coverage. |
python/pyarrow/tests/test_scalars.py |
Tests scalar values and null conversion. |
python/pyarrow/tests/test_misc.py |
Adds interval classes to shared checks. |
python/pyarrow/tests/test_compute.py |
Tests interval compute-result wrappers and values. |
python/pyarrow/src/arrow/python/helpers.cc |
Extends primitive type lookup. |
python/pyarrow/scalar.pxi |
Implements and registers the new scalar classes. |
python/pyarrow/lib.pyx |
Groups interval type constants together. |
python/pyarrow/lib.pxd |
Declares the new array classes. |
python/pyarrow/includes/libarrow.pxd |
Adds C++ interval scalar bindings. |
python/pyarrow/array.pxi |
Implements and registers the new array classes. |
python/pyarrow/__init__.py |
Exports the new public APIs. |
docs/source/python/api/datatypes.rst |
Lists the new type factories. |
docs/source/python/api/arrays.rst |
Lists the new array and scalar classes. |
Review effort: Balanced
| return datetime.timedelta(microseconds=sp.value // 1000) | ||
|
|
||
|
|
||
| cdef class MonthIntervalScalar(Scalar): |
There was a problem hiding this comment.
Yeah, current __reduce__ needs the Python-to-Arrow conversion which I am workin on next (follow-up PR). We can add the change proposed here or wait for the follow-up PR where the round-trip will not raise an error and we can add a test there.
There was a problem hiding this comment.
🔵 Needs a closer look
Both new interval scalar classes use an unsupported Python-value reconstruction path, causing pickle round-trips and shallow/deep copies to raise ArrowNotImplementedError even for null scalars.
1 open issue
Review effort: Balanced
| if not scalar.is_valid: | ||
| return None | ||
|
|
||
| return (scalar.value.days, scalar.value.milliseconds) |
There was a problem hiding this comment.
I wonder if a NamedTuple or dataclass would be better here for explicitness
| if not scalar.is_valid: | ||
| return None | ||
|
|
||
| return scalar.value |
There was a problem hiding this comment.
I think this could also be a namedtuple, perhaps, or maybe that's excessive.

Rationale for this change
month_day_nano_intervalis supported by PyArrow but other interval types are missing (day_time_intervalandmonth_interval).What changes are included in this PR?
The changes made by Joris in jorisvandenbossche@97a0953:
month_interval()andday_time_interval()factoriespa.types.is_intervalfor all three interval typesPicking up where Joris has left off I added:
as_py()on both scalar classes,Current decisions:
MonthIntervalScalar.as_py()returnsint(number of months)DayTimeIntervalScalar.as_py()returns plain tuple (days, milliseconds) with the raw values.A possible follow-up (or a change in this PR if preferred) would be a named tuple, e.g. pa.
DayTime(days, milliseconds).Planned follow-ups:
pa.scalar,pa.arrayfrom Python valuesto_numpy(),to_pandas(): returning object dtype with theas_py()values (or timedelta64[M] for months)Are these changes tested?
Yes.
Are there any user-facing changes?
No.
Was AI used for this PR?
PR code and description written by:
Reviewed before submission by: