2020)
2121from pandas .tests .io .pytables .common import (
2222 _maybe_remove ,
23- ensure_clean_store ,
2423)
2524
2625from pandas .io .pytables import Term
@@ -45,7 +44,7 @@ def test_select_columns_in_where(setup_path):
4544 columns = ["A" , "B" , "C" ],
4645 )
4746
48- with ensure_clean_store (setup_path ) as store :
47+ with HDFStore (setup_path , mode = "w" ) as store :
4948 store .put ("df" , df , format = "table" )
5049 expected = df [["A" ]]
5150
@@ -55,7 +54,7 @@ def test_select_columns_in_where(setup_path):
5554
5655 # With a Series
5756 s = Series (np .random .default_rng (2 ).standard_normal (10 ), index = index , name = "A" )
58- with ensure_clean_store (setup_path ) as store :
57+ with HDFStore (setup_path , mode = "w" ) as store :
5958 store .put ("s" , s , format = "table" )
6059 tm .assert_series_equal (store .select ("s" , where = "columns=['A']" ), s )
6160
@@ -67,7 +66,7 @@ def test_select_with_dups(setup_path):
6766 )
6867 df .index = date_range ("20130101 9:30" , periods = 10 , freq = "min" , unit = "ns" )
6968
70- with ensure_clean_store (setup_path ) as store :
69+ with HDFStore (setup_path , mode = "w" ) as store :
7170 store .append ("df" , df )
7271
7372 result = store .select ("df" )
@@ -98,7 +97,7 @@ def test_select_with_dups(setup_path):
9897 )
9998 df .index = date_range ("20130101 9:30" , periods = 10 , freq = "min" , unit = "ns" )
10099
101- with ensure_clean_store (setup_path ) as store :
100+ with HDFStore (setup_path , mode = "w" ) as store :
102101 store .append ("df" , df )
103102
104103 result = store .select ("df" )
@@ -118,7 +117,7 @@ def test_select_with_dups(setup_path):
118117 tm .assert_frame_equal (result , expected , by_blocks = True )
119118
120119 # duplicates on both index and columns
121- with ensure_clean_store (setup_path ) as store :
120+ with HDFStore (setup_path , mode = "w" ) as store :
122121 store .append ("df" , df )
123122 store .append ("df" , df )
124123
@@ -129,7 +128,7 @@ def test_select_with_dups(setup_path):
129128
130129
131130def test_select (setup_path ):
132- with ensure_clean_store (setup_path ) as store :
131+ with HDFStore (setup_path , mode = "w" ) as store :
133132 # select with columns=
134133 df = DataFrame (
135134 np .random .default_rng (2 ).standard_normal ((10 , 4 )),
@@ -170,7 +169,7 @@ def test_select(setup_path):
170169
171170
172171def test_select_dtypes (setup_path , request ):
173- with ensure_clean_store (setup_path ) as store :
172+ with HDFStore (setup_path , mode = "w" ) as store :
174173 # with a Timestamp data column (GH #2637)
175174 df = DataFrame (
176175 {
@@ -232,7 +231,7 @@ def test_select_dtypes(setup_path, request):
232231 expected = df .reindex (index = list (df .index )[0 :10 ], columns = ["A" ])
233232 tm .assert_frame_equal (expected , result )
234233
235- with ensure_clean_store (setup_path ) as store :
234+ with HDFStore (setup_path , mode = "w" ) as store :
236235 # floats w/o NaN
237236 df = DataFrame ({"cols" : range (11 ), "values" : range (11 )}, dtype = "float64" )
238237 df ["cols" ] = (df ["cols" ] + 10 ).apply (str )
@@ -270,7 +269,7 @@ def test_select_dtypes(setup_path, request):
270269
271270 # test selection with comparison against numpy scalar
272271 # GH 11283
273- with ensure_clean_store (setup_path ) as store :
272+ with HDFStore (setup_path , mode = "w" ) as store :
274273 df = DataFrame (
275274 1.1 * np .arange (120 ).reshape ((30 , 4 )),
276275 columns = Index (list ("ABCD" )),
@@ -293,7 +292,7 @@ def test_select_dtypes(setup_path, request):
293292
294293
295294def test_select_with_many_inputs (setup_path ):
296- with ensure_clean_store (setup_path ) as store :
295+ with HDFStore (setup_path , mode = "w" ) as store :
297296 df = DataFrame (
298297 {
299298 "ts" : bdate_range ("2012-01-01" , periods = 300 , unit = "ns" ),
@@ -342,7 +341,7 @@ def test_select_with_many_inputs(setup_path):
342341
343342def test_select_iterator (tmp_path , setup_path ):
344343 # single table
345- with ensure_clean_store (setup_path ) as store :
344+ with HDFStore (setup_path ) as store :
346345 df = DataFrame (
347346 np .random .default_rng (2 ).standard_normal ((10 , 4 )),
348347 columns = Index (list ("ABCD" )),
@@ -400,7 +399,7 @@ def test_select_iterator(tmp_path, setup_path):
400399
401400 # multiple
402401
403- with ensure_clean_store (setup_path ) as store :
402+ with HDFStore (setup_path ) as store :
404403 df1 = DataFrame (
405404 np .random .default_rng (2 ).standard_normal ((10 , 4 )),
406405 columns = Index (list ("ABCD" )),
@@ -428,7 +427,7 @@ def test_select_iterator_complete_8014(setup_path):
428427 chunksize = 1e4
429428
430429 # no iterator
431- with ensure_clean_store (setup_path ) as store :
430+ with HDFStore (setup_path ) as store :
432431 expected = DataFrame (
433432 np .random .default_rng (2 ).standard_normal ((100064 , 4 )),
434433 columns = Index (list ("ABCD" )),
@@ -463,7 +462,7 @@ def test_select_iterator_complete_8014(setup_path):
463462 tm .assert_frame_equal (expected , result )
464463
465464 # with iterator, full range
466- with ensure_clean_store (setup_path ) as store :
465+ with HDFStore (setup_path ) as store :
467466 expected = DataFrame (
468467 np .random .default_rng (2 ).standard_normal ((100064 , 4 )),
469468 columns = Index (list ("ABCD" )),
@@ -505,7 +504,7 @@ def test_select_iterator_non_complete_8014(setup_path):
505504 chunksize = 1e4
506505
507506 # with iterator, non complete range
508- with ensure_clean_store (setup_path ) as store :
507+ with HDFStore (setup_path ) as store :
509508 expected = DataFrame (
510509 np .random .default_rng (2 ).standard_normal ((100064 , 4 )),
511510 columns = Index (list ("ABCD" )),
@@ -539,7 +538,7 @@ def test_select_iterator_non_complete_8014(setup_path):
539538 tm .assert_frame_equal (rexpected , result )
540539
541540 # with iterator, empty where
542- with ensure_clean_store (setup_path ) as store :
541+ with HDFStore (setup_path ) as store :
543542 expected = DataFrame (
544543 np .random .default_rng (2 ).standard_normal ((100064 , 4 )),
545544 columns = Index (list ("ABCD" )),
@@ -563,7 +562,7 @@ def test_select_iterator_many_empty_frames(setup_path):
563562 chunksize = 10_000
564563
565564 # with iterator, range limited to the first chunk
566- with ensure_clean_store (setup_path ) as store :
565+ with HDFStore (setup_path ) as store :
567566 expected = DataFrame (
568567 np .random .default_rng (2 ).standard_normal ((100064 , 4 )),
569568 columns = Index (list ("ABCD" )),
@@ -622,7 +621,7 @@ def test_frame_select(setup_path, request):
622621 index = date_range ("2000-01-01" , periods = 10 , freq = "B" , unit = "ns" ),
623622 )
624623
625- with ensure_clean_store (setup_path ) as store :
624+ with HDFStore (setup_path ) as store :
626625 store .put ("frame" , df , format = "table" )
627626 date = df .index [len (df ) // 2 ]
628627
@@ -675,7 +674,7 @@ def test_frame_select_complex(setup_path):
675674 df ["string" ] = "foo"
676675 df .loc [df .index [0 :4 ], "string" ] = "bar"
677676
678- with ensure_clean_store (setup_path ) as store :
677+ with HDFStore (setup_path ) as store :
679678 store .put ("df" , df , format = "table" , data_columns = ["string" ])
680679
681680 # empty
@@ -790,7 +789,7 @@ def test_invalid_filtering(setup_path):
790789 index = date_range ("2000-01-01" , periods = 10 , freq = "B" , unit = "ns" ),
791790 )
792791
793- with ensure_clean_store (setup_path ) as store :
792+ with HDFStore (setup_path ) as store :
794793 store .put ("df" , df , format = "table" )
795794
796795 msg = "unable to collapse Joint Filters"
@@ -805,7 +804,7 @@ def test_invalid_filtering(setup_path):
805804
806805def test_string_select (setup_path ):
807806 # GH 2973
808- with ensure_clean_store (setup_path ) as store :
807+ with HDFStore (setup_path ) as store :
809808 df = DataFrame (
810809 np .random .default_rng (2 ).standard_normal ((10 , 4 )),
811810 columns = Index (list ("ABCD" )),
@@ -858,7 +857,7 @@ def test_select_as_multiple(setup_path):
858857 df2 = df1 .copy ().rename (columns = "{}_2" .format )
859858 df2 ["foo" ] = "bar"
860859
861- with ensure_clean_store (setup_path ) as store :
860+ with HDFStore (setup_path ) as store :
862861 msg = "keys must be a list/tuple"
863862 # no tables stored
864863 with pytest .raises (TypeError , match = msg ):
@@ -925,7 +924,7 @@ def test_select_as_multiple(setup_path):
925924
926925
927926def test_nan_selection_bug_4858 (setup_path ):
928- with ensure_clean_store (setup_path ) as store :
927+ with HDFStore (setup_path ) as store :
929928 df = DataFrame ({"cols" : range (6 ), "values" : range (6 )}, dtype = "float64" )
930929 df ["cols" ] = (df ["cols" ] + 10 ).apply (str )
931930 df .iloc [0 ] = np .nan
@@ -949,7 +948,7 @@ def test_query_with_nested_special_character(setup_path):
949948 }
950949 )
951950 expected = df [df .a == "test & test" ]
952- with ensure_clean_store (setup_path ) as store :
951+ with HDFStore (setup_path ) as store :
953952 store .append ("test" , df , format = "table" , data_columns = True )
954953 result = store .select ("test" , 'a = "test & test"' )
955954 tm .assert_frame_equal (expected , result )
@@ -959,7 +958,7 @@ def test_query_long_float_literal(setup_path):
959958 # GH 14241
960959 df = DataFrame ({"A" : [1000000000.0009 , 1000000000.0011 , 1000000000.0015 ]})
961960
962- with ensure_clean_store (setup_path ) as store :
961+ with HDFStore (setup_path ) as store :
963962 store .append ("test" , df , format = "table" , data_columns = True )
964963
965964 cutoff = 1000000000.0006
@@ -989,7 +988,7 @@ def test_query_compare_column_type(setup_path):
989988 columns = ["date" , "real_date" , "float" , "int" ],
990989 )
991990
992- with ensure_clean_store (setup_path ) as store :
991+ with HDFStore (setup_path ) as store :
993992 store .append ("test" , df , format = "table" , data_columns = True )
994993
995994 ts = Timestamp ("2014-01-01" ) # noqa: F841
0 commit comments