@@ -1859,13 +1859,57 @@ def test_op_duplicate_index(self):
1859
1859
assert_series_equal (result , expected )
1860
1860
1861
1861
def test_argminmax (self ):
1862
- # GH13595
1863
-
1864
- # Expected behavior for arg min/max in the presence of NA and Inf
1862
+ # Series.argmin, Series.argmax are aliased to Series.idxmin,
1863
+ # Series.idxmax
1864
+
1865
+ # Expected behavior for empty Series
1866
+ s = pd .Series ([])
1867
+
1868
+ with pytest .raises (ValueError ):
1869
+ s .argmin ()
1870
+ with pytest .raises (ValueError ):
1871
+ s .argmin (skipna = False )
1872
+ with pytest .raises (ValueError ):
1873
+ s .argmax ()
1874
+ with pytest .raises (ValueError ):
1875
+ s .argmax (skipna = False )
1876
+
1877
+ # For numeric data with NA and Inf (GH #13595)
1865
1878
s = pd .Series ([0 , - np .inf , np .inf , np .nan ])
1866
1879
1867
1880
assert s .argmin () == 1
1868
1881
assert np .isnan (s .argmin (skipna = False ))
1869
1882
1870
1883
assert s .argmax () == 2
1871
1884
assert np .isnan (s .argmax (skipna = False ))
1885
+
1886
+ # Using old-style behavior that treat floating point nan, -inf, and
1887
+ # +inf as missing
1888
+ s = pd .Series ([0 , - np .inf , np .inf , np .nan ])
1889
+
1890
+ with pd .option_context ('mode.use_inf_as_null' , True ):
1891
+ assert s .argmin () == 0
1892
+ assert np .isnan (s .argmin (skipna = False ))
1893
+ assert s .argmax () == 0
1894
+ np .isnan (s .argmax (skipna = False ))
1895
+
1896
+ # For non-NA strings
1897
+ s = pd .Series (['foo' , 'foo' , 'bar' , 'bar' , 'baz' ])
1898
+
1899
+ assert s .argmin () == 2
1900
+ assert s .argmin (skipna = False ) == 2
1901
+
1902
+ assert s .argmax () == 0
1903
+ assert s .argmax (skipna = False ) == 0
1904
+
1905
+ # For mixed string and NA
1906
+ s = pd .Series (['foo' , 'foo' , 'bar' , 'bar' , None , np .nan , 'baz' ])
1907
+
1908
+ with pytest .raises (TypeError ):
1909
+ s .argmin ()
1910
+ with pytest .raises (TypeError ):
1911
+ s .argmin (skipna = False )
1912
+ with pytest .raises (TypeError ):
1913
+ s .argmax ()
1914
+ with pytest .raises (TypeError ):
1915
+ s .argmax (skipna = False )
0 commit comments