Skip to content

Commit

Permalink
Use dt units in empty() (tz path) (#893)
Browse files Browse the repository at this point in the history
* Use dt units in empty()

* simplfiying suggestion

* fix
  • Loading branch information
martindurant authored Oct 23, 2023
1 parent 165bec3 commit 3cf97b7
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions fastparquet/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from pandas import (
Categorical, DataFrame, Series,
CategoricalIndex, RangeIndex, Index, MultiIndex,
DatetimeIndex, CategoricalDtype
DatetimeIndex, CategoricalDtype,
DatetimeTZDtype
)
from pandas.core.arrays.masked import BaseMaskedDtype
import warnings
Expand Down Expand Up @@ -195,9 +196,10 @@ def set_cats(values, i=i, col=col, **kwargs):

values = Categorical.from_codes(codes=code, dtype=bvalues.dtype)

elif getattr(bvalues.dtype, 'tz', None):
values = np.zeros(shape=shape, dtype='M8[ns]')
values = type(bvalues)(values, dtype=bvalues.dtype)
elif isinstance(bvalues.dtype, DatetimeTZDtype):
dt = "M8[ns]" if PANDAS_VERSION.major < 2 else f'M8[{bvalues.dtype.unit}]'
values = np.zeros(shape=shape, dtype=dt)
values = type(bvalues)._from_sequence(values, copy=False, dtype=bvalues.dtype)
else:
if not isinstance(bvalues, np.ndarray):
# e.g. DatetimeLikeBlock backed by DatetimeArray/TimedeltaArray
Expand Down

0 comments on commit 3cf97b7

Please sign in to comment.