@@ -65,27 +65,58 @@ def test_ops(self, opname, obj):
6565 assert result .value == expected
6666
6767 @pytest .mark .parametrize ("opname" , ["max" , "min" ])
68- def test_nanops (self , opname , index_or_series ):
68+ @pytest .mark .parametrize (
69+ "dtype, val" ,
70+ [
71+ ("object" , 2.0 ),
72+ ("float64" , 2.0 ),
73+ ("datetime64[ns]" , datetime (2011 , 11 , 1 )),
74+ ("Int64" , 2 ),
75+ ("boolean" , True ),
76+ ],
77+ )
78+ def test_nanminmax (self , opname , dtype , val , index_or_series ):
6979 # GH#7261
7080 klass = index_or_series
71- arg_op = "arg" + opname if klass is Index else "idx" + opname
7281
73- obj = klass ([ np . nan , 2.0 ])
74- assert getattr ( obj , opname )() == 2.0
82+ if dtype in [ "Int64" , "boolean" ] and klass == pd . Index :
83+ pytest . skip ( "EAs can't yet be stored in an index" )
7584
76- obj = klass ([np .nan ])
77- assert pd .isna (getattr (obj , opname )())
78- assert pd .isna (getattr (obj , opname )(skipna = False ))
85+ def check_missing (res ):
86+ if dtype == "datetime64[ns]" :
87+ return res is pd .NaT
88+ elif dtype == "Int64" :
89+ return res is pd .NA
90+ else :
91+ return pd .isna (res )
7992
80- obj = klass ([], dtype = object )
81- assert pd . isna (getattr (obj , opname )())
82- assert pd . isna (getattr (obj , opname )(skipna = False ))
93+ obj = klass ([None ], dtype = dtype )
94+ assert check_missing (getattr (obj , opname )())
95+ assert check_missing (getattr (obj , opname )(skipna = False ))
8396
84- obj = klass ([pd .NaT , datetime (2011 , 11 , 1 )])
85- # check DatetimeIndex monotonic path
86- assert getattr (obj , opname )() == datetime (2011 , 11 , 1 )
87- assert getattr (obj , opname )(skipna = False ) is pd .NaT
97+ obj = klass ([], dtype = dtype )
98+ assert check_missing (getattr (obj , opname )())
99+ assert check_missing (getattr (obj , opname )(skipna = False ))
100+
101+ if dtype == "object" :
102+ # generic test with object only works for empty / all NaN
103+ return
104+
105+ obj = klass ([None , val ], dtype = dtype )
106+ assert getattr (obj , opname )() == val
107+ assert check_missing (getattr (obj , opname )(skipna = False ))
88108
109+ obj = klass ([None , val , None ], dtype = dtype )
110+ assert getattr (obj , opname )() == val
111+ assert check_missing (getattr (obj , opname )(skipna = False ))
112+
113+ @pytest .mark .parametrize ("opname" , ["max" , "min" ])
114+ def test_nanargminmax (self , opname , index_or_series ):
115+ # GH#7261
116+ klass = index_or_series
117+ arg_op = "arg" + opname if klass is Index else "idx" + opname
118+
119+ obj = klass ([pd .NaT , datetime (2011 , 11 , 1 )])
89120 assert getattr (obj , arg_op )() == 1
90121 result = getattr (obj , arg_op )(skipna = False )
91122 if klass is Series :
@@ -95,9 +126,6 @@ def test_nanops(self, opname, index_or_series):
95126
96127 obj = klass ([pd .NaT , datetime (2011 , 11 , 1 ), pd .NaT ])
97128 # check DatetimeIndex non-monotonic path
98- assert getattr (obj , opname )(), datetime (2011 , 11 , 1 )
99- assert getattr (obj , opname )(skipna = False ) is pd .NaT
100-
101129 assert getattr (obj , arg_op )() == 1
102130 result = getattr (obj , arg_op )(skipna = False )
103131 if klass is Series :
0 commit comments