Skip to content

Commit 9999269

Browse files
author
Daniel Grady
committed
Add separate tests for argmin/max under Python 2 and 3
1 parent 8671bf6 commit 9999269

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

pandas/tests/series/test_operators.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from datetime import datetime, timedelta
99
import operator
1010
from itertools import product, starmap
11+
import sys
1112

1213
from numpy import nan, inf
1314
import numpy as np
@@ -1883,7 +1884,7 @@ def test_argminmax(self):
18831884
assert s.argmax() == 2
18841885
assert np.isnan(s.argmax(skipna=False))
18851886

1886-
# Using old-style behavior that treat floating point nan, -inf, and
1887+
# Using old-style behavior that treats floating point nan, -inf, and
18871888
# +inf as missing
18881889
s = pd.Series([0, -np.inf, np.inf, np.nan])
18891890

@@ -1903,13 +1904,23 @@ def test_argminmax(self):
19031904
assert s.argmax(skipna=False) == 0
19041905

19051906
# 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.
19061911
s = pd.Series(['foo', 'foo', 'bar', 'bar', None, np.nan, 'baz'])
19071912

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

Comments
 (0)