-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: HDFStore failures on timezone-aware data #20595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2695,30 +2695,24 @@ def write_array(self, key, value, items=None): | |
_tables().ObjectAtom()) | ||
vlarr.append(value) | ||
else: | ||
if empty_array: | ||
if is_datetime64_dtype(value.dtype): | ||
self._handle.create_array(self.group, key, value.view('i8')) | ||
getattr(self.group, key)._v_attrs.value_type = 'datetime64' | ||
elif is_datetime64tz_dtype(value.dtype): | ||
# store as UTC | ||
# with a zone | ||
self._handle.create_array(self.group, key, value.asi8) | ||
|
||
node = getattr(self.group, key) | ||
node._v_attrs.tz = _get_tz(value.tz) | ||
node._v_attrs.value_type = 'datetime64' | ||
elif is_timedelta64_dtype(value.dtype): | ||
self._handle.create_array(self.group, key, value.view('i8')) | ||
getattr(self.group, key)._v_attrs.value_type = 'timedelta64' | ||
elif empty_array: | ||
self.write_array_empty(key, value) | ||
else: | ||
if is_datetime64_dtype(value.dtype): | ||
self._handle.create_array( | ||
self.group, key, value.view('i8')) | ||
getattr( | ||
self.group, key)._v_attrs.value_type = 'datetime64' | ||
elif is_datetime64tz_dtype(value.dtype): | ||
# store as UTC | ||
# with a zone | ||
self._handle.create_array(self.group, key, | ||
value.asi8) | ||
|
||
node = getattr(self.group, key) | ||
node._v_attrs.tz = _get_tz(value.tz) | ||
node._v_attrs.value_type = 'datetime64' | ||
elif is_timedelta64_dtype(value.dtype): | ||
self._handle.create_array( | ||
self.group, key, value.view('i8')) | ||
getattr( | ||
self.group, key)._v_attrs.value_type = 'timedelta64' | ||
else: | ||
self._handle.create_array(self.group, key, value) | ||
self._handle.create_array(self.group, key, value) | ||
|
||
getattr(self.group, key)._v_attrs.transposed = transposed | ||
|
||
|
@@ -2771,7 +2765,11 @@ def read(self, **kwargs): | |
def write(self, obj, **kwargs): | ||
super(SeriesFixed, self).write(obj, **kwargs) | ||
self.write_index('index', obj.index) | ||
self.write_array('values', obj.values) | ||
if is_datetime64tz_dtype(obj.dtype): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is reaching into the internal implementation way too much. you can use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so |
||
values = obj._data.blocks[0].values | ||
else: | ||
values = obj.values | ||
self.write_array('values', values) | ||
self.attrs.name = obj.name | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2792,10 +2792,22 @@ def test_empty_series_frame(self): | |
self._check_roundtrip(df1, tm.assert_frame_equal) | ||
self._check_roundtrip(df2, tm.assert_frame_equal) | ||
|
||
def test_empty_series(self): | ||
for dtype in [np.int64, np.float64, np.object, 'm8[ns]', 'M8[ns]']: | ||
s = Series(dtype=dtype) | ||
self._check_roundtrip(s, tm.assert_series_equal) | ||
@pytest.mark.parametrize('dtype', [ | ||
np.int64, np.float64, np.object, 'm8[ns]', 'M8[ns]', | ||
'datetime64[ns, UTC]' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add US/Eastern as well |
||
]) | ||
def test_empty_series(self, dtype): | ||
s = Series(dtype=dtype) | ||
self._check_roundtrip(s, tm.assert_series_equal) | ||
|
||
def test_series_timezone(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. parameterize these both with US/Eastern as well |
||
s = Series([0], dtype='datetime64[ns, UTC]') | ||
self._check_roundtrip(s, tm.assert_series_equal) | ||
|
||
def test_empty_frame_timezone(self): | ||
s = Series(dtype='datetime64[ns, UTC]') | ||
df = DataFrame({'A': s}) | ||
self._check_roundtrip(df, tm.assert_frame_equal) | ||
|
||
def test_can_serialize_dates(self): | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not very clear, is this for Series generally and empty DataFrames? this is only for a fixed store.