@@ -4888,6 +4888,45 @@ def test_unsuppored_hdf_file_error(self, datapath):
4888
4888
with pytest .raises (ValueError , match = message ):
4889
4889
pd .read_hdf (data_path )
4890
4890
4891
+ def test_supported_for_subclasses_dataframe (self ):
4892
+ class SubDataFrame (DataFrame ):
4893
+ @property
4894
+ def _constructor (self ):
4895
+ return SubDataFrame
4896
+ data = {'a' : [1 , 2 ], 'b' : [3 , 4 ]}
4897
+ sdf = SubDataFrame (data , dtype = np .intp )
4898
+
4899
+ expected = np .array ([[1 , 3 ], [2 , 4 ]], dtype = np .intp )
4900
+
4901
+ with ensure_clean_path ("temp.h5" ) as path :
4902
+ sdf .to_hdf (path , "df" )
4903
+ result = read_hdf (path , "df" ).values
4904
+ assert np .array_equal (result , expected )
4905
+
4906
+ with ensure_clean_path ("temp.h5" ) as path :
4907
+ with HDFStore (path ) as store :
4908
+ store .put ("df" , sdf )
4909
+ result = read_hdf (path , "df" ).values
4910
+ assert np .array_equal (result , expected )
4911
+
4912
+ def test_supported_for_subclasses_series (self ):
4913
+ class SubSeries (Series ):
4914
+ @property
4915
+ def _constructor (self ):
4916
+ return SubSeries
4917
+ sser = SubSeries ([1 , 2 , 3 ], dtype = np .intp )
4918
+
4919
+ expected = np .array ([1 , 2 , 3 ], dtype = np .intp )
4920
+
4921
+ with ensure_clean_path ("temp.h5" ) as path :
4922
+ sser .to_hdf (path , "ser" )
4923
+
4924
+ with ensure_clean_path ("temp.h5" ) as path :
4925
+ with HDFStore (path ) as store :
4926
+ store .put ("ser" , sser )
4927
+ result = read_hdf (path , "ser" ).values
4928
+ assert np .array_equal (result , expected )
4929
+
4891
4930
4892
4931
@pytest .mark .parametrize ("bad_version" , [(1 , 2 ), (1 ,), [], "12" , "123" ])
4893
4932
def test_maybe_adjust_name_bad_version_raises (bad_version ):
0 commit comments