Skip to content

Commit b2b6d0c

Browse files
TomAugspurgerkornilova203
authored andcommitted
COMPAT: Remove use of private re attribute (pandas-dev#20553)
1 parent 82cf120 commit b2b6d0c

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

pandas/compat/__init__.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
# pylint disable=W0611
2727
# flake8: noqa
2828

29+
import re
2930
import functools
3031
import itertools
3132
from distutils.version import LooseVersion
@@ -136,7 +137,6 @@ def lfilter(*args, **kwargs):
136137

137138
else:
138139
# Python 2
139-
import re
140140
_name_re = re.compile(r"[a-zA-Z_][a-zA-Z0-9_]*$")
141141

142142
FileNotFoundError = IOError
@@ -423,6 +423,14 @@ def raise_with_traceback(exc, traceback=Ellipsis):
423423
parse_date = _date_parser.parse
424424

425425

426+
# In Python 3.7, the private re._pattern_type is removed.
427+
# Python 3.5+ have typing.re.Pattern
428+
if PY35:
429+
import typing
430+
re_type = typing.re.Pattern
431+
else:
432+
re_type = type(re.compile(''))
433+
426434
# https://github.com/pandas-dev/pandas/pull/9123
427435
def is_platform_little_endian():
428436
""" am I little endian """

pandas/core/dtypes/inference.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from collections import Iterable
77
from numbers import Number
88
from pandas.compat import (PY2, string_types, text_type,
9-
string_and_binary_types)
9+
string_and_binary_types, re_type)
1010
from pandas._libs import lib
1111

1212
is_bool = lib.is_bool
@@ -216,7 +216,7 @@ def is_re(obj):
216216
False
217217
"""
218218

219-
return isinstance(obj, re._pattern_type)
219+
return isinstance(obj, re_type)
220220

221221

222222
def is_re_compilable(obj):

0 commit comments

Comments
 (0)