Skip to content

Commit 6b93c4a

Browse files
GH-38341: [Python] Remove usage of pandas internals DatetimeTZBlock (#38321)
### Rationale for this change This usage probably stems from a long time ago that it was required to specify the Block type, but nowadays it's good enough to just specify the dtype, and thus cutting down on our usage of internal pandas objects. Part of #35081 * Closes: #38341 Authored-by: Joris Van den Bossche <jorisvandenbossche@gmail.com> Signed-off-by: Joris Van den Bossche <jorisvandenbossche@gmail.com>
1 parent 6d44906 commit 6b93c4a

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

python/pyarrow/pandas_compat.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -717,9 +717,15 @@ def _reconstruct_block(item, columns=None, extension_columns=None):
717717
elif 'timezone' in item:
718718
unit, _ = np.datetime_data(block_arr.dtype)
719719
dtype = make_datetimetz(unit, item['timezone'])
720-
block = _int.make_block(block_arr, placement=placement,
721-
klass=_int.DatetimeTZBlock,
722-
dtype=dtype)
720+
if _pandas_api.is_ge_v21():
721+
pd_arr = _pandas_api.pd.array(
722+
block_arr.view("int64"), dtype=dtype, copy=False
723+
)
724+
block = _int.make_block(pd_arr, placement=placement)
725+
else:
726+
block = _int.make_block(block_arr, placement=placement,
727+
klass=_int.DatetimeTZBlock,
728+
dtype=dtype)
723729
elif 'py_array' in item:
724730
# create ExtensionBlock
725731
arr = item['py_array']

0 commit comments

Comments
 (0)