|
17 | 17 |
|
18 | 18 | import pandas as pd
|
19 | 19 | from pandas import (
|
20 |
| - Categorical, DataFrame, DatetimeIndex, Index, Int64Index, MultiIndex, |
21 |
| - RangeIndex, Series, Timestamp, bdate_range, concat, date_range, isna, |
22 |
| - timedelta_range) |
| 20 | + Categorical, CategoricalIndex, DataFrame, DatetimeIndex, Index, Int64Index, |
| 21 | + MultiIndex, RangeIndex, Series, Timestamp, bdate_range, concat, date_range, |
| 22 | + isna, timedelta_range) |
23 | 23 | import pandas.util.testing as tm
|
24 | 24 | from pandas.util.testing import (
|
25 | 25 | assert_frame_equal, assert_series_equal, set_timezone)
|
@@ -4749,6 +4749,19 @@ def test_select_empty_where(self, where):
|
4749 | 4749 | result = pd.read_hdf(store, "df", where=where)
|
4750 | 4750 | assert_frame_equal(result, df)
|
4751 | 4751 |
|
| 4752 | + @pytest.mark.parametrize('idx', [ |
| 4753 | + date_range('2019', freq='D', periods=3, tz='UTC'), |
| 4754 | + CategoricalIndex(list('abc')) |
| 4755 | + ]) |
| 4756 | + def test_to_hdf_multiindex_extension_dtype(self, idx): |
| 4757 | + # GH 7775 |
| 4758 | + mi = MultiIndex.from_arrays([idx, idx]) |
| 4759 | + df = pd.DataFrame(0, index=mi, columns=['a']) |
| 4760 | + with ensure_clean_path(self.path) as path: |
| 4761 | + with pytest.raises(NotImplementedError, |
| 4762 | + match="Saving a MultiIndex"): |
| 4763 | + df.to_hdf(path, 'df') |
| 4764 | + |
4752 | 4765 |
|
4753 | 4766 | class TestHDFComplexValues(Base):
|
4754 | 4767 | # GH10447
|
@@ -5170,3 +5183,20 @@ def test_dst_transitions(self):
|
5170 | 5183 | store.append('df', df)
|
5171 | 5184 | result = store.select('df')
|
5172 | 5185 | assert_frame_equal(result, df)
|
| 5186 | + |
| 5187 | + def test_read_with_where_tz_aware_index(self): |
| 5188 | + # GH 11926 |
| 5189 | + periods = 10 |
| 5190 | + dts = pd.date_range('20151201', periods=periods, |
| 5191 | + freq='D', tz='UTC') |
| 5192 | + mi = pd.MultiIndex.from_arrays([dts, range(periods)], |
| 5193 | + names=['DATE', 'NO']) |
| 5194 | + expected = pd.DataFrame({'MYCOL': 0}, index=mi) |
| 5195 | + |
| 5196 | + key = 'mykey' |
| 5197 | + with ensure_clean_path(self.path) as path: |
| 5198 | + with pd.HDFStore(path) as store: |
| 5199 | + store.append(key, expected, format='table', append=True) |
| 5200 | + result = pd.read_hdf(path, key, |
| 5201 | + where="DATE > 20151130") |
| 5202 | + assert_frame_equal(result, expected) |
0 commit comments