25
25
ensure_clean_store ,
26
26
)
27
27
28
- pytestmark = [
29
- pytest .mark .single_cpu ,
30
- pytest .mark .xfail (using_string_dtype (), reason = "TODO(infer_string)" , strict = False ),
31
- ]
28
+ pytestmark = [pytest .mark .single_cpu ]
32
29
33
30
tables = pytest .importorskip ("tables" )
34
31
@@ -40,7 +37,7 @@ def test_append(setup_path):
40
37
# tables.NaturalNameWarning):
41
38
df = DataFrame (
42
39
np .random .default_rng (2 ).standard_normal ((20 , 4 )),
43
- columns = Index (list ("ABCD" ), dtype = object ),
40
+ columns = Index (list ("ABCD" )),
44
41
index = date_range ("2000-01-01" , periods = 20 , freq = "B" ),
45
42
)
46
43
_maybe_remove (store , "df1" )
@@ -203,7 +200,7 @@ def test_append_some_nans(setup_path):
203
200
tm .assert_frame_equal (store ["df3" ], df3 , check_index_type = True )
204
201
205
202
206
- def test_append_all_nans (setup_path ):
203
+ def test_append_all_nans (setup_path , using_infer_string ):
207
204
with ensure_clean_store (setup_path ) as store :
208
205
df = DataFrame (
209
206
{
@@ -255,7 +252,13 @@ def test_append_all_nans(setup_path):
255
252
_maybe_remove (store , "df" )
256
253
store .append ("df" , df [:10 ], dropna = True )
257
254
store .append ("df" , df [10 :], dropna = True )
258
- tm .assert_frame_equal (store ["df" ], df , check_index_type = True )
255
+ result = store ["df" ]
256
+ expected = df
257
+ if using_infer_string :
258
+ # TODO: Test is incorrect when not using_infer_string.
259
+ # Should take the last 4 rows uncondiationally.
260
+ expected = expected [- 4 :]
261
+ tm .assert_frame_equal (result , expected , check_index_type = True )
259
262
260
263
_maybe_remove (store , "df2" )
261
264
store .append ("df2" , df [:10 ], dropna = False )
@@ -294,7 +297,7 @@ def test_append_frame_column_oriented(setup_path, request):
294
297
# column oriented
295
298
df = DataFrame (
296
299
np .random .default_rng (2 ).standard_normal ((10 , 4 )),
297
- columns = Index (list ("ABCD" ), dtype = object ),
300
+ columns = Index (list ("ABCD" )),
298
301
index = date_range ("2000-01-01" , periods = 10 , freq = "B" ),
299
302
)
300
303
df .index = df .index ._with_freq (None ) # freq doesn't round-trip
@@ -426,7 +429,7 @@ def check_col(key, name, size):
426
429
{
427
430
"A" : [0.0 , 1.0 , 2.0 , 3.0 , 4.0 ],
428
431
"B" : [0.0 , 1.0 , 0.0 , 1.0 , 0.0 ],
429
- "C" : Index (["foo1" , "foo2" , "foo3" , "foo4" , "foo5" ], dtype = object ),
432
+ "C" : Index (["foo1" , "foo2" , "foo3" , "foo4" , "foo5" ]),
430
433
"D" : date_range ("20130101" , periods = 5 ),
431
434
}
432
435
).set_index ("C" )
@@ -453,7 +456,7 @@ def check_col(key, name, size):
453
456
_maybe_remove (store , "df" )
454
457
df = DataFrame (
455
458
np .random .default_rng (2 ).standard_normal ((10 , 4 )),
456
- columns = Index (list ("ABCD" ), dtype = object ),
459
+ columns = Index (list ("ABCD" )),
457
460
index = date_range ("2000-01-01" , periods = 10 , freq = "B" ),
458
461
)
459
462
df ["string" ] = "foo"
@@ -513,11 +516,12 @@ def test_append_with_empty_string(setup_path):
513
516
tm .assert_frame_equal (store .select ("df" ), df )
514
517
515
518
519
+ @pytest .mark .xfail (using_string_dtype (), reason = "TODO(infer_string)" )
516
520
def test_append_with_data_columns (setup_path ):
517
521
with ensure_clean_store (setup_path ) as store :
518
522
df = DataFrame (
519
523
np .random .default_rng (2 ).standard_normal ((10 , 4 )),
520
- columns = Index (list ("ABCD" ), dtype = object ),
524
+ columns = Index (list ("ABCD" )),
521
525
index = date_range ("2000-01-01" , periods = 10 , freq = "B" ),
522
526
)
523
527
df .iloc [0 , df .columns .get_loc ("B" )] = 1.0
@@ -693,8 +697,8 @@ def test_append_misc(setup_path):
693
697
with ensure_clean_store (setup_path ) as store :
694
698
df = DataFrame (
695
699
1.1 * np .arange (120 ).reshape ((30 , 4 )),
696
- columns = Index (list ("ABCD" ), dtype = object ),
697
- index = Index ([f"i-{ i } " for i in range (30 )], dtype = object ),
700
+ columns = Index (list ("ABCD" )),
701
+ index = Index ([f"i-{ i } " for i in range (30 )]),
698
702
)
699
703
store .append ("df" , df , chunksize = 1 )
700
704
result = store .select ("df" )
@@ -710,8 +714,8 @@ def test_append_misc_chunksize(setup_path, chunksize):
710
714
# more chunksize in append tests
711
715
df = DataFrame (
712
716
1.1 * np .arange (120 ).reshape ((30 , 4 )),
713
- columns = Index (list ("ABCD" ), dtype = object ),
714
- index = Index ([f"i-{ i } " for i in range (30 )], dtype = object ),
717
+ columns = Index (list ("ABCD" )),
718
+ index = Index ([f"i-{ i } " for i in range (30 )]),
715
719
)
716
720
df ["string" ] = "foo"
717
721
df ["float322" ] = 1.0
@@ -747,15 +751,15 @@ def test_append_misc_empty_frame(setup_path):
747
751
tm .assert_frame_equal (store .select ("df2" ), df )
748
752
749
753
750
- def test_append_raise (setup_path ):
754
+ def test_append_raise (setup_path , using_infer_string ):
751
755
with ensure_clean_store (setup_path ) as store :
752
756
# test append with invalid input to get good error messages
753
757
754
758
# list in column
755
759
df = DataFrame (
756
760
1.1 * np .arange (120 ).reshape ((30 , 4 )),
757
- columns = Index (list ("ABCD" ), dtype = object ),
758
- index = Index ([f"i-{ i } " for i in range (30 )], dtype = object ),
761
+ columns = Index (list ("ABCD" )),
762
+ index = Index ([f"i-{ i } " for i in range (30 )]),
759
763
)
760
764
df ["invalid" ] = [["a" ]] * len (df )
761
765
assert df .dtypes ["invalid" ] == np .object_
@@ -775,8 +779,8 @@ def test_append_raise(setup_path):
775
779
# datetime with embedded nans as object
776
780
df = DataFrame (
777
781
1.1 * np .arange (120 ).reshape ((30 , 4 )),
778
- columns = Index (list ("ABCD" ), dtype = object ),
779
- index = Index ([f"i-{ i } " for i in range (30 )], dtype = object ),
782
+ columns = Index (list ("ABCD" )),
783
+ index = Index ([f"i-{ i } " for i in range (30 )]),
780
784
)
781
785
s = Series (datetime .datetime (2001 , 1 , 2 ), index = df .index )
782
786
s = s .astype (object )
@@ -803,8 +807,8 @@ def test_append_raise(setup_path):
803
807
# appending an incompatible table
804
808
df = DataFrame (
805
809
1.1 * np .arange (120 ).reshape ((30 , 4 )),
806
- columns = Index (list ("ABCD" ), dtype = object ),
807
- index = Index ([f"i-{ i } " for i in range (30 )], dtype = object ),
810
+ columns = Index (list ("ABCD" )),
811
+ index = Index ([f"i-{ i } " for i in range (30 )]),
808
812
)
809
813
store .append ("df" , df )
810
814
@@ -881,7 +885,7 @@ def test_append_with_timedelta(setup_path):
881
885
def test_append_to_multiple (setup_path ):
882
886
df1 = DataFrame (
883
887
np .random .default_rng (2 ).standard_normal ((10 , 4 )),
884
- columns = Index (list ("ABCD" ), dtype = object ),
888
+ columns = Index (list ("ABCD" )),
885
889
index = date_range ("2000-01-01" , periods = 10 , freq = "B" ),
886
890
)
887
891
df2 = df1 .copy ().rename (columns = "{}_2" .format )
@@ -918,12 +922,12 @@ def test_append_to_multiple(setup_path):
918
922
def test_append_to_multiple_dropna (setup_path ):
919
923
df1 = DataFrame (
920
924
np .random .default_rng (2 ).standard_normal ((10 , 4 )),
921
- columns = Index (list ("ABCD" ), dtype = object ),
925
+ columns = Index (list ("ABCD" )),
922
926
index = date_range ("2000-01-01" , periods = 10 , freq = "B" ),
923
927
)
924
928
df2 = DataFrame (
925
929
np .random .default_rng (2 ).standard_normal ((10 , 4 )),
926
- columns = Index (list ("ABCD" ), dtype = object ),
930
+ columns = Index (list ("ABCD" )),
927
931
index = date_range ("2000-01-01" , periods = 10 , freq = "B" ),
928
932
).rename (columns = "{}_2" .format )
929
933
df1 .iloc [1 , df1 .columns .get_indexer (["A" , "B" ])] = np .nan
@@ -943,7 +947,7 @@ def test_append_to_multiple_dropna(setup_path):
943
947
def test_append_to_multiple_dropna_false (setup_path ):
944
948
df1 = DataFrame (
945
949
np .random .default_rng (2 ).standard_normal ((10 , 4 )),
946
- columns = Index (list ("ABCD" ), dtype = object ),
950
+ columns = Index (list ("ABCD" )),
947
951
index = date_range ("2000-01-01" , periods = 10 , freq = "B" ),
948
952
)
949
953
df2 = df1 .copy ().rename (columns = "{}_2" .format )
0 commit comments