Skip to content

Commit b62a870

Browse files
authored
Merge branch 'master' into GH37105
2 parents 3142b8b + a838759 commit b62a870

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

doc/source/whatsnew/v1.2.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ I/O
434434
- Bug in :meth:`read_parquet` with fixed offset timezones. String representation of timezones was not recognized (:issue:`35997`, :issue:`36004`)
435435
- Bug in output rendering of complex numbers showing too many trailing zeros (:issue:`36799`)
436436
- Bug in :meth:`DataFrame.to_parquet` now returns bytes when no ``path`` argument is passed (:issue:`37105`)
437+
- 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`)
437438

438439
Plotting
439440
^^^^^^^^

pandas/core/indexes/range.py

+9
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,15 @@ def any(self, *args, **kwargs) -> bool:
811811

812812
# --------------------------------------------------------------------
813813

814+
def _cmp_method(self, other, op):
815+
if isinstance(other, RangeIndex) and self._range == other._range:
816+
if op in {operator.eq, operator.le, operator.ge}:
817+
return np.ones(len(self), dtype=bool)
818+
elif op in {operator.ne, operator.lt, operator.gt}:
819+
return np.zeros(len(self), dtype=bool)
820+
821+
return super()._cmp_method(other, op)
822+
814823
def _arith_method(self, other, op):
815824
"""
816825
Parameters

pandas/io/pytables.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3027,8 +3027,6 @@ def write_array(self, key: str, value: ArrayLike, items: Optional[Index] = None)
30273027
vlarr = self._handle.create_vlarray(self.group, key, _tables().ObjectAtom())
30283028
vlarr.append(value)
30293029

3030-
elif empty_array:
3031-
self.write_array_empty(key, value)
30323030
elif is_datetime64_dtype(value.dtype):
30333031
self._handle.create_array(self.group, key, value.view("i8"))
30343032
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)
30433041
elif is_timedelta64_dtype(value.dtype):
30443042
self._handle.create_array(self.group, key, value.view("i8"))
30453043
getattr(self.group, key)._v_attrs.value_type = "timedelta64"
3044+
elif empty_array:
3045+
self.write_array_empty(key, value)
30463046
else:
30473047
self._handle.create_array(self.group, key, value)
30483048

pandas/tests/io/pytables/test_timezones.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ def test_tseries_select_index_column(setup_path):
268268
assert rng.tz == result.dt.tz
269269

270270

271-
def test_timezones_fixed(setup_path):
271+
def test_timezones_fixed_format_frame_non_empty(setup_path):
272272
with ensure_clean_store(setup_path) as store:
273273

274274
# index
@@ -296,6 +296,16 @@ def test_timezones_fixed(setup_path):
296296
tm.assert_frame_equal(result, df)
297297

298298

299+
@pytest.mark.parametrize("dtype", ["datetime64[ns, UTC]", "datetime64[ns, US/Eastern]"])
300+
def test_timezones_fixed_format_frame_empty(setup_path, dtype):
301+
with ensure_clean_store(setup_path) as store:
302+
s = Series(dtype=dtype)
303+
df = DataFrame({"A": s})
304+
store["df"] = df
305+
result = store["df"]
306+
tm.assert_frame_equal(result, df)
307+
308+
299309
def test_fixed_offset_tz(setup_path):
300310
rng = date_range("1/1/2000 00:00:00-07:00", "1/30/2000 00:00:00-07:00")
301311
frame = DataFrame(np.random.randn(len(rng), 4), index=rng)

0 commit comments

Comments
 (0)