Skip to content

BUG: IntervalDtype Arrow round-trip for tz-aware datetime subtypes - #66291

Open
ShashwatAgrawal20 wants to merge 2 commits into
pandas-dev:mainfrom
ShashwatAgrawal20:bug-64297-interval-arrow-tz
Open

BUG: IntervalDtype Arrow round-trip for tz-aware datetime subtypes#66291
ShashwatAgrawal20 wants to merge 2 commits into
pandas-dev:mainfrom
ShashwatAgrawal20:bug-64297-interval-arrow-tz

Conversation

@ShashwatAgrawal20

Copy link
Copy Markdown
Contributor

Problem description

IntervalDtype.__from_arrow__ used np.asarray(..., dtype=self.subtype), which raises for timezone-aware datetime subtypes:

TypeError: Cannot interpret 'datetime64[us, Europe/Brussels]' as a data type

IntervalArray.__arrow_array__ also failed for the same subtype via pyarrow.from_numpy_dtype, and ArrowIntervalType deserialization could not reconstruct tz-aware timestamp subtypes with type_for_alias.

Solution

  1. Convert Arrow left/right fields via the subtype's __from_arrow__ when the subtype is an extension dtype (e.g. DatetimeTZDtype).
  2. Teach IntervalArray.__arrow_array__ to emit tz-aware timestamp fields for DatetimeTZDtype bounds.
  3. Deserialize ArrowIntervalType from the storage type's field type so tz-aware timestamps round-trip.

…H#64297)

IntervalDtype.__from_arrow__ used np.asarray with the subtype, which fails
for DatetimeTZDtype. Convert extension subtypes via __from_arrow__ instead,
support tz intervals in IntervalArray.__arrow_array__, and deserialize
ArrowIntervalType from the storage type so tz-aware timestamps work.
…onversion

mypy rejected self._left._ndarray because bounds are typed as a union
including ndarray; assert DatetimeArray for the DatetimeTZDtype path.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IntervalDtype.__from_arrow__ raises a TypeError when subtype is a nullable ExtensionDtype

1 participant