From 862017f8202285953ad7ca2d2e49038add1a850e Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Fri, 30 Mar 2018 11:46:33 -0500 Subject: [PATCH 1/3] COMPAT: Remove use of private re attribute Closes https://github.com/pandas-dev/pandas/issues/20551 --- pandas/compat/__init__.py | 6 ++++++ pandas/core/dtypes/inference.py | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pandas/compat/__init__.py b/pandas/compat/__init__.py index aefa1ddd6cf0b..6fc11d49e6b7d 100644 --- a/pandas/compat/__init__.py +++ b/pandas/compat/__init__.py @@ -423,6 +423,12 @@ def raise_with_traceback(exc, traceback=Ellipsis): parse_date = _date_parser.parse +if PY36: + 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): From 0dfce2258f1ce794ad828182ea11524a94990558 Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Fri, 30 Mar 2018 13:20:23 -0500 Subject: [PATCH 2/3] Added a note --- pandas/compat/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/compat/__init__.py b/pandas/compat/__init__.py index 6fc11d49e6b7d..984adb167a9f5 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,7 @@ def raise_with_traceback(exc, traceback=Ellipsis): parse_date = _date_parser.parse +# In Python 3.7, the private re._pattern_type is removed. if PY36: import typing re_type = typing.re.Pattern From 7681282352aab31f57eb98a87694e279b2366831 Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Fri, 30 Mar 2018 15:08:25 -0500 Subject: [PATCH 3/3] Use right lower bound --- pandas/compat/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/compat/__init__.py b/pandas/compat/__init__.py index 984adb167a9f5..8885064b22ea8 100644 --- a/pandas/compat/__init__.py +++ b/pandas/compat/__init__.py @@ -424,7 +424,8 @@ def raise_with_traceback(exc, traceback=Ellipsis): # In Python 3.7, the private re._pattern_type is removed. -if PY36: +# Python 3.5+ have typing.re.Pattern +if PY35: import typing re_type = typing.re.Pattern else: