8
8
from datetime import datetime , timedelta
9
9
import operator
10
10
from itertools import product , starmap
11
+ import sys
11
12
12
13
from numpy import nan , inf
13
14
import numpy as np
@@ -1883,7 +1884,7 @@ def test_argminmax(self):
1883
1884
assert s .argmax () == 2
1884
1885
assert np .isnan (s .argmax (skipna = False ))
1885
1886
1886
- # Using old-style behavior that treat floating point nan, -inf, and
1887
+ # Using old-style behavior that treats floating point nan, -inf, and
1887
1888
# +inf as missing
1888
1889
s = pd .Series ([0 , - np .inf , np .inf , np .nan ])
1889
1890
@@ -1903,13 +1904,23 @@ def test_argminmax(self):
1903
1904
assert s .argmax (skipna = False ) == 0
1904
1905
1905
1906
# For mixed string and NA
1907
+ # This works differently under Python 2 and 3: under Python 2,
1908
+ # comparing strings and None, for example, is valid, and we can
1909
+ # compute an argmax. Under Python 3, such comparisons are not valid
1910
+ # and raise a TypeError.
1906
1911
s = pd .Series (['foo' , 'foo' , 'bar' , 'bar' , None , np .nan , 'baz' ])
1907
1912
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 )
1913
+ if sys .version_info [0 ] < 3 :
1914
+ assert s .argmin () == 4
1915
+ assert np .isnan (s .argmin (skipna = False ))
1916
+ assert s .argmax () == 0
1917
+ assert np .isnan (s .argmax (skipna = False ))
1918
+ else :
1919
+ with pytest .raises (TypeError ):
1920
+ s .argmin ()
1921
+ with pytest .raises (TypeError ):
1922
+ s .argmin (skipna = False )
1923
+ with pytest .raises (TypeError ):
1924
+ s .argmax ()
1925
+ with pytest .raises (TypeError ):
1926
+ s .argmax (skipna = False )
0 commit comments