File tree 2 files changed +31
-0
lines changed
2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -904,6 +904,21 @@ def select(
904
904
# create the storer and axes
905
905
where = _ensure_term (where , scope_level = 1 )
906
906
s = self ._create_storer (group )
907
+
908
+ # Raise an error if trying to query tz-aware index
909
+ if where is not None :
910
+ try :
911
+ index = s .obj .index
912
+ if hasattr (index , "tz" ) and index .tz is not None :
913
+ raise ValueError (
914
+ "Filtering with `where=` on timezone-aware indexes is not supported "
915
+ "in HDFStore."
916
+ )
917
+
918
+ except AttributeError :
919
+ # some storer types (e.g. Legacy format) may not have `obj`; skip check
920
+ pass
921
+
907
922
s .infer_axes ()
908
923
909
924
# function to call on iteration
Original file line number Diff line number Diff line change
1
+ import pytest
2
+
3
+ import pandas as pd
4
+
5
+
6
+ @pytest .mark .parametrize ("tz" , ["US/Eastern" , "Europe/Berlin" ])
7
+ def test_hdf_where_query_on_tzindex_raises (tmp_path , tz ):
8
+ df = pd .DataFrame ({"x" : range (5 )})
9
+ df ["dt" ] = pd .date_range ("2020-01-01" , periods = 5 , tz = tz )
10
+ df = df .set_index ("dt" )
11
+
12
+ file_path = tmp_path / "test.h5"
13
+ df .to_hdf (file_path , key = "df" , format = "table" )
14
+
15
+ with pytest .raises (ValueError , match = "invalid variable reference" ):
16
+ pd .read_hdf (file_path , key = "df" , where = 'dt=="2020-01-03 00:00:00-05:00"' )
You can’t perform that action at this time.
0 commit comments