@@ -550,31 +550,36 @@ class TestQuantileExtensionDtype:
550
550
),
551
551
pd .period_range ("2016-01-01" , periods = 9 , freq = "D" ),
552
552
pd .date_range ("2016-01-01" , periods = 9 , tz = "US/Pacific" ),
553
- pytest .param (
554
- pd .array (np .arange (9 ), dtype = "Int64" ),
555
- marks = pytest .mark .xfail (reason = "doesn't implement from_factorized" ),
556
- ),
557
- pytest .param (
558
- pd .array (np .arange (9 ), dtype = "Float64" ),
559
- marks = pytest .mark .xfail (reason = "doesn't implement from_factorized" ),
560
- ),
553
+ pd .array (np .arange (9 ), dtype = "Int64" ),
554
+ pd .array (np .arange (9 ), dtype = "Float64" ),
561
555
],
562
556
ids = lambda x : str (x .dtype ),
563
557
)
564
558
def index (self , request ):
559
+ # NB: not actually an Index object
565
560
idx = request .param
566
561
idx .name = "A"
567
562
return idx
568
563
564
+ @pytest .fixture
565
+ def obj (self , index , frame_or_series ):
566
+ # bc index is not always an Index (yet), we need to re-patch .name
567
+ obj = frame_or_series (index ).copy ()
568
+
569
+ if frame_or_series is Series :
570
+ obj .name = "A"
571
+ else :
572
+ obj .columns = ["A" ]
573
+ return obj
574
+
569
575
def compute_quantile (self , obj , qs ):
570
576
if isinstance (obj , Series ):
571
577
result = obj .quantile (qs )
572
578
else :
573
579
result = obj .quantile (qs , numeric_only = False )
574
580
return result
575
581
576
- def test_quantile_ea (self , index , frame_or_series ):
577
- obj = frame_or_series (index ).copy ()
582
+ def test_quantile_ea (self , obj , index ):
578
583
579
584
# result should be invariant to shuffling
580
585
indexer = np .arange (len (index ), dtype = np .intp )
@@ -585,13 +590,14 @@ def test_quantile_ea(self, index, frame_or_series):
585
590
result = self .compute_quantile (obj , qs )
586
591
587
592
# expected here assumes len(index) == 9
588
- expected = Series ([index [4 ], index [0 ], index [- 1 ]], index = qs , name = "A" )
589
- expected = frame_or_series (expected )
593
+ expected = Series (
594
+ [index [4 ], index [0 ], index [- 1 ]], dtype = index .dtype , index = qs , name = "A"
595
+ )
596
+ expected = type (obj )(expected )
590
597
591
598
tm .assert_equal (result , expected )
592
599
593
- def test_quantile_ea_with_na (self , index , frame_or_series ):
594
- obj = frame_or_series (index ).copy ()
600
+ def test_quantile_ea_with_na (self , obj , index ):
595
601
596
602
obj .iloc [0 ] = index ._na_value
597
603
obj .iloc [- 1 ] = index ._na_value
@@ -605,15 +611,15 @@ def test_quantile_ea_with_na(self, index, frame_or_series):
605
611
result = self .compute_quantile (obj , qs )
606
612
607
613
# expected here assumes len(index) == 9
608
- expected = Series ([index [4 ], index [1 ], index [- 2 ]], index = qs , name = "A" )
609
- expected = frame_or_series (expected )
614
+ expected = Series (
615
+ [index [4 ], index [1 ], index [- 2 ]], dtype = index .dtype , index = qs , name = "A"
616
+ )
617
+ expected = type (obj )(expected )
610
618
tm .assert_equal (result , expected )
611
619
612
620
# TODO: filtering can be removed after GH#39763 is fixed
613
621
@pytest .mark .filterwarnings ("ignore:Using .astype to convert:FutureWarning" )
614
- def test_quantile_ea_all_na (self , index , frame_or_series ):
615
-
616
- obj = frame_or_series (index ).copy ()
622
+ def test_quantile_ea_all_na (self , obj , index , frame_or_series ):
617
623
618
624
obj .iloc [:] = index ._na_value
619
625
@@ -630,13 +636,12 @@ def test_quantile_ea_all_na(self, index, frame_or_series):
630
636
result = self .compute_quantile (obj , qs )
631
637
632
638
expected = index .take ([- 1 , - 1 , - 1 ], allow_fill = True , fill_value = index ._na_value )
633
- expected = Series (expected , index = qs )
634
- expected = frame_or_series (expected )
639
+ expected = Series (expected , index = qs , name = "A" )
640
+ expected = type ( obj ) (expected )
635
641
tm .assert_equal (result , expected )
636
642
637
- def test_quantile_ea_scalar (self , index , frame_or_series ):
643
+ def test_quantile_ea_scalar (self , obj , index ):
638
644
# scalar qs
639
- obj = frame_or_series (index ).copy ()
640
645
641
646
# result should be invariant to shuffling
642
647
indexer = np .arange (len (index ), dtype = np .intp )
@@ -646,8 +651,8 @@ def test_quantile_ea_scalar(self, index, frame_or_series):
646
651
qs = 0.5
647
652
result = self .compute_quantile (obj , qs )
648
653
649
- expected = Series ({"A" : index [4 ]}, name = 0.5 )
650
- if frame_or_series is Series :
654
+ expected = Series ({"A" : index [4 ]}, dtype = index . dtype , name = 0.5 )
655
+ if isinstance ( obj , Series ) :
651
656
expected = expected ["A" ]
652
657
assert result == expected
653
658
else :
0 commit comments