1
1
import numpy as np
2
2
import pytest
3
3
4
- from pandas ._config import using_string_dtype
5
-
6
4
import pandas as pd
7
5
from pandas import (
8
6
DataFrame ,
@@ -326,7 +324,6 @@ def test_quantile_multi_empty(self, interp_method):
326
324
)
327
325
tm .assert_frame_equal (result , expected )
328
326
329
- @pytest .mark .xfail (using_string_dtype (), reason = "TODO(infer_string)" )
330
327
def test_quantile_datetime (self , unit ):
331
328
dti = pd .to_datetime (["2010" , "2011" ]).as_unit (unit )
332
329
df = DataFrame ({"a" : dti , "b" : [0 , 5 ]})
@@ -373,14 +370,13 @@ def test_quantile_datetime(self, unit):
373
370
374
371
# empty when numeric_only=True
375
372
result = df [["a" , "c" ]].quantile (0.5 , numeric_only = True )
376
- expected = Series ([], index = [] , dtype = np .float64 , name = 0.5 )
373
+ expected = Series ([], index = Index ([], dtype = "str" ) , dtype = np .float64 , name = 0.5 )
377
374
tm .assert_series_equal (result , expected )
378
375
379
376
result = df [["a" , "c" ]].quantile ([0.5 ], numeric_only = True )
380
- expected = DataFrame (index = [0.5 ], columns = [] )
377
+ expected = DataFrame (index = [0.5 ], columns = Index ([], dtype = "str" ) )
381
378
tm .assert_frame_equal (result , expected )
382
379
383
- @pytest .mark .xfail (using_string_dtype (), reason = "TODO(infer_string)" )
384
380
@pytest .mark .parametrize (
385
381
"dtype" ,
386
382
[
@@ -398,7 +394,7 @@ def test_quantile_dt64_empty(self, dtype, interp_method):
398
394
res = df .quantile (
399
395
0.5 , axis = 1 , numeric_only = False , interpolation = interpolation , method = method
400
396
)
401
- expected = Series ([], index = [] , name = 0.5 , dtype = dtype )
397
+ expected = Series ([], index = Index ([], dtype = "str" ) , name = 0.5 , dtype = dtype )
402
398
tm .assert_series_equal (res , expected )
403
399
404
400
# no columns in result, so no dtype preservation
@@ -409,7 +405,7 @@ def test_quantile_dt64_empty(self, dtype, interp_method):
409
405
interpolation = interpolation ,
410
406
method = method ,
411
407
)
412
- expected = DataFrame (index = [0.5 ], columns = [] )
408
+ expected = DataFrame (index = [0.5 ], columns = Index ([], dtype = "str" ) )
413
409
tm .assert_frame_equal (res , expected )
414
410
415
411
@pytest .mark .parametrize ("invalid" , [- 1 , 2 , [0.5 , - 1 ], [0.5 , 2 ]])
@@ -645,7 +641,6 @@ def test_quantile_nat(self, interp_method, unit):
645
641
)
646
642
tm .assert_frame_equal (res , exp )
647
643
648
- @pytest .mark .xfail (using_string_dtype (), reason = "TODO(infer_string)" )
649
644
def test_quantile_empty_no_rows_floats (self , interp_method ):
650
645
interpolation , method = interp_method
651
646
@@ -660,11 +655,11 @@ def test_quantile_empty_no_rows_floats(self, interp_method):
660
655
tm .assert_frame_equal (res , exp )
661
656
662
657
res = df .quantile (0.5 , axis = 1 , interpolation = interpolation , method = method )
663
- exp = Series ([], index = [] , dtype = "float64" , name = 0.5 )
658
+ exp = Series ([], index = Index ([], dtype = "str" ) , dtype = "float64" , name = 0.5 )
664
659
tm .assert_series_equal (res , exp )
665
660
666
661
res = df .quantile ([0.5 ], axis = 1 , interpolation = interpolation , method = method )
667
- exp = DataFrame (columns = [] , index = [0.5 ])
662
+ exp = DataFrame (columns = Index ([], dtype = "str" ) , index = [0.5 ])
668
663
tm .assert_frame_equal (res , exp )
669
664
670
665
def test_quantile_empty_no_rows_ints (self , interp_method ):
@@ -874,7 +869,6 @@ def test_quantile_ea_scalar(self, request, obj, index):
874
869
else :
875
870
tm .assert_series_equal (result , expected )
876
871
877
- @pytest .mark .xfail (using_string_dtype (), reason = "TODO(infer_string)" , strict = False )
878
872
@pytest .mark .parametrize (
879
873
"dtype, expected_data, expected_index, axis" ,
880
874
[
@@ -889,11 +883,13 @@ def test_empty_numeric(self, dtype, expected_data, expected_index, axis):
889
883
df = DataFrame (columns = ["a" , "b" ], dtype = dtype )
890
884
result = df .quantile (0.5 , axis = axis )
891
885
expected = Series (
892
- expected_data , name = 0.5 , index = Index (expected_index ), dtype = "float64"
886
+ expected_data ,
887
+ name = 0.5 ,
888
+ index = Index (expected_index , dtype = "str" ),
889
+ dtype = "float64" ,
893
890
)
894
891
tm .assert_series_equal (result , expected )
895
892
896
- @pytest .mark .xfail (using_string_dtype (), reason = "TODO(infer_string)" , strict = False )
897
893
@pytest .mark .parametrize (
898
894
"dtype, expected_data, expected_index, axis, expected_dtype" ,
899
895
[
@@ -908,11 +904,13 @@ def test_empty_datelike(
908
904
df = DataFrame (columns = ["a" , "b" ], dtype = dtype )
909
905
result = df .quantile (0.5 , axis = axis , numeric_only = False )
910
906
expected = Series (
911
- expected_data , name = 0.5 , index = Index (expected_index ), dtype = expected_dtype
907
+ expected_data ,
908
+ name = 0.5 ,
909
+ index = Index (expected_index , dtype = "str" ),
910
+ dtype = expected_dtype ,
912
911
)
913
912
tm .assert_series_equal (result , expected )
914
913
915
- @pytest .mark .xfail (using_string_dtype (), reason = "TODO(infer_string)" , strict = False )
916
914
@pytest .mark .parametrize (
917
915
"expected_data, expected_index, axis" ,
918
916
[
@@ -931,7 +929,10 @@ def test_datelike_numeric_only(self, expected_data, expected_index, axis):
931
929
)
932
930
result = df [["a" , "c" ]].quantile (0.5 , axis = axis , numeric_only = True )
933
931
expected = Series (
934
- expected_data , name = 0.5 , index = Index (expected_index ), dtype = np .float64
932
+ expected_data ,
933
+ name = 0.5 ,
934
+ index = Index (expected_index , dtype = "str" if axis == 0 else "int64" ),
935
+ dtype = np .float64 ,
935
936
)
936
937
tm .assert_series_equal (result , expected )
937
938
0 commit comments