Skip to content

TST: more 3.6 test fixing #14684

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pandas/compat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
PY2 = sys.version_info[0] == 2
PY3 = (sys.version_info[0] >= 3)
PY35 = (sys.version_info >= (3, 5))
PY36 = (sys.version_info >= (3, 6))

try:
import __builtin__ as builtins
Expand Down
3 changes: 2 additions & 1 deletion pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
is_sequence,
is_scalar,
is_sparse,
_is_unorderable_exception,
_ensure_platform_int)
from pandas.types.missing import isnull, _infer_fill_value

Expand Down Expand Up @@ -1411,7 +1412,7 @@ def error():
except TypeError as e:

# python 3 type errors should be raised
if 'unorderable' in str(e): # pragma: no cover
if _is_unorderable_exception(e):
error()
raise
except:
Expand Down
3 changes: 2 additions & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
is_iterator,
is_dict_like,
is_scalar,
_is_unorderable_exception,
_ensure_platform_int)
from pandas.types.generic import ABCSparseArray, ABCDataFrame
from pandas.types.cast import (_maybe_upcast, _infer_dtype_from_scalar,
Expand Down Expand Up @@ -753,7 +754,7 @@ def setitem(key, value):
raise ValueError("Can only tuple-index with a MultiIndex")

# python 3 type errors should be raised
if 'unorderable' in str(e): # pragma: no cover
if _is_unorderable_exception(e):
raise IndexError(key)

if com.is_bool_indexer(key):
Expand Down
21 changes: 17 additions & 4 deletions pandas/tests/indexes/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .common import Base

from pandas.compat import (is_platform_windows, range, lrange, lzip, u,
zip, PY3)
zip, PY3, PY36)
import operator
import os

Expand Down Expand Up @@ -1774,7 +1774,12 @@ def create_index(self):
def test_order(self):
idx = self.create_index()
# 9816 deprecated
if PY3:
if PY36:
with tm.assertRaisesRegexp(TypeError, "'>' not supported "
"between instances of 'str' and 'int'"):
with tm.assert_produces_warning(FutureWarning):
idx.order()
elif PY3:
with tm.assertRaisesRegexp(TypeError, "unorderable types"):
with tm.assert_produces_warning(FutureWarning):
idx.order()
Expand All @@ -1784,7 +1789,11 @@ def test_order(self):

def test_argsort(self):
idx = self.create_index()
if PY3:
if PY36:
with tm.assertRaisesRegexp(TypeError, "'>' not supported "
"between instances of 'str' and 'int'"):
result = idx.argsort()
elif PY3:
with tm.assertRaisesRegexp(TypeError, "unorderable types"):
result = idx.argsort()
else:
Expand All @@ -1794,7 +1803,11 @@ def test_argsort(self):

def test_numpy_argsort(self):
idx = self.create_index()
if PY3:
if PY36:
with tm.assertRaisesRegexp(TypeError, "'>' not supported "
"between instances of 'str' and 'int'"):
result = np.argsort(idx)
elif PY3:
with tm.assertRaisesRegexp(TypeError, "unorderable types"):
result = np.argsort(idx)
else:
Expand Down
3 changes: 2 additions & 1 deletion pandas/tslib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1539,7 +1539,8 @@ cdef convert_to_tsobject(object ts, object tz, object unit,
"Cannot convert Period to Timestamp "
"unambiguously. Use to_timestamp")
else:
raise TypeError('Cannot convert input to Timestamp')
raise TypeError('Cannot convert input [{}] of type {} to '
'Timestamp'.format(ts, type(ts)))

if obj.value != NPY_NAT:
_check_dts_bounds(&obj.dts)
Expand Down
17 changes: 16 additions & 1 deletion pandas/types/common.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
""" common type operations """

import numpy as np
from pandas.compat import string_types, text_type, binary_type
from pandas.compat import (string_types, text_type, binary_type,
PY3, PY36)
from pandas import lib, algos
from .dtypes import (CategoricalDtype, CategoricalDtypeType,
DatetimeTZDtype, DatetimeTZDtypeType,
Expand Down Expand Up @@ -188,6 +189,20 @@ def is_datetime_or_timedelta_dtype(arr_or_dtype):
return issubclass(tipo, (np.datetime64, np.timedelta64))


def _is_unorderable_exception(e):
"""
return a boolean if we an unorderable exception error message

These are different error message for PY>=3<=3.5 and PY>=3.6
"""
if PY36:
return ("'>' not supported between instances "
"of 'str' and 'int'" in str(e))
elif PY3:
return 'unorderable' in str(e)
return False


def is_numeric_v_string_like(a, b):
"""
numpy doesn't like to compare numeric arrays vs scalar string-likes
Expand Down