diff --git a/pandas/compat/__init__.py b/pandas/compat/__init__.py index aefa1ddd6cf0b..8885064b22ea8 100644 --- a/pandas/compat/__init__.py +++ b/pandas/compat/__init__.py @@ -26,6 +26,7 @@ # pylint disable=W0611 # flake8: noqa +import re import functools import itertools from distutils.version import LooseVersion @@ -136,7 +137,6 @@ def lfilter(*args, **kwargs): else: # Python 2 - import re _name_re = re.compile(r"[a-zA-Z_][a-zA-Z0-9_]*$") FileNotFoundError = IOError @@ -423,6 +423,14 @@ def raise_with_traceback(exc, traceback=Ellipsis): parse_date = _date_parser.parse +# In Python 3.7, the private re._pattern_type is removed. +# Python 3.5+ have typing.re.Pattern +if PY35: + import typing + re_type = typing.re.Pattern +else: + re_type = type(re.compile('')) + # https://github.com/pandas-dev/pandas/pull/9123 def is_platform_little_endian(): """ am I little endian """ diff --git a/pandas/core/dtypes/inference.py b/pandas/core/dtypes/inference.py index a02f0c5b2a4d6..d747e69d1ff39 100644 --- a/pandas/core/dtypes/inference.py +++ b/pandas/core/dtypes/inference.py @@ -6,7 +6,7 @@ from collections import Iterable from numbers import Number from pandas.compat import (PY2, string_types, text_type, - string_and_binary_types) + string_and_binary_types, re_type) from pandas._libs import lib is_bool = lib.is_bool @@ -216,7 +216,7 @@ def is_re(obj): False """ - return isinstance(obj, re._pattern_type) + return isinstance(obj, re_type) def is_re_compilable(obj):