From bc16438f8aa796c3d79578c716fedc35babf9e5e Mon Sep 17 00:00:00 2001 From: arw2019 Date: Mon, 12 Oct 2020 04:50:27 +0000 Subject: [PATCH 1/3] BUG: set tz info before writing empty array --- pandas/io/pytables.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index 5160773455067..ffc3a4501470f 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -3027,8 +3027,6 @@ def write_array(self, key: str, value: ArrayLike, items: Optional[Index] = None) vlarr = self._handle.create_vlarray(self.group, key, _tables().ObjectAtom()) vlarr.append(value) - elif empty_array: - self.write_array_empty(key, value) elif is_datetime64_dtype(value.dtype): self._handle.create_array(self.group, key, value.view("i8")) getattr(self.group, key)._v_attrs.value_type = "datetime64" @@ -3043,6 +3041,8 @@ def write_array(self, key: str, value: ArrayLike, items: Optional[Index] = None) 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: self._handle.create_array(self.group, key, value) From 9965eb30fa001bfe0e119275f13ff0a43eeabebd Mon Sep 17 00:00:00 2001 From: arw2019 Date: Mon, 12 Oct 2020 05:00:23 +0000 Subject: [PATCH 2/3] TST: HDF5 roundtrip of empty tz-aware dataframe --- pandas/tests/io/pytables/test_timezones.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pandas/tests/io/pytables/test_timezones.py b/pandas/tests/io/pytables/test_timezones.py index dc28e9543f19e..bcc5dcf9f5181 100644 --- a/pandas/tests/io/pytables/test_timezones.py +++ b/pandas/tests/io/pytables/test_timezones.py @@ -268,7 +268,7 @@ def test_tseries_select_index_column(setup_path): assert rng.tz == result.dt.tz -def test_timezones_fixed(setup_path): +def test_timezones_fixed_format_frame_non_empty(setup_path): with ensure_clean_store(setup_path) as store: # index @@ -296,6 +296,16 @@ def test_timezones_fixed(setup_path): tm.assert_frame_equal(result, df) +@pytest.mark.parametrize("dtype", ["datetime64[ns, UTC]", "datetime64[ns, US/Eastern]"]) +def test_timezones_fixed_format_frame_empty(setup_path, dtype): + with ensure_clean_store(setup_path) as store: + s = Series(dtype=dtype) + df = DataFrame({"A": s}) + store["df"] = df + result = store["df"] + tm.assert_frame_equal(result, df) + + def test_fixed_offset_tz(setup_path): rng = date_range("1/1/2000 00:00:00-07:00", "1/30/2000 00:00:00-07:00") frame = DataFrame(np.random.randn(len(rng), 4), index=rng) From a3524bd2eab4ef2d7b25f2a313affc264cbccaee Mon Sep 17 00:00:00 2001 From: arw2019 Date: Thu, 15 Oct 2020 04:30:32 +0000 Subject: [PATCH 3/3] add whatsnew --- doc/source/whatsnew/v1.2.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v1.2.0.rst b/doc/source/whatsnew/v1.2.0.rst index 339cda4db48fb..9fc094330fb36 100644 --- a/doc/source/whatsnew/v1.2.0.rst +++ b/doc/source/whatsnew/v1.2.0.rst @@ -433,6 +433,7 @@ I/O - Bug in :meth:`to_json` with ``lines=True`` and ``orient='records'`` the last line of the record is not appended with 'new line character' (:issue:`36888`) - Bug in :meth:`read_parquet` with fixed offset timezones. String representation of timezones was not recognized (:issue:`35997`, :issue:`36004`) - Bug in output rendering of complex numbers showing too many trailing zeros (:issue:`36799`) +- Bug in :class:`HDFStore` threw a ``TypeError`` when exporting an empty :class:`DataFrame` with ``datetime64[ns, tz]`` dtypes with a fixed HDF5 store (:issue:`20594`) Plotting ^^^^^^^^