Skip to content

COMPAT: Remove use of private re attribute #20553

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

Merged
merged 3 commits into from
Mar 31, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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
9 changes: 8 additions & 1 deletion pandas/compat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
# pylint disable=W0611
# flake8: noqa

import re
import functools
import itertools
from distutils.version import LooseVersion
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -423,6 +423,13 @@ def raise_with_traceback(exc, traceback=Ellipsis):
parse_date = _date_parser.parse


# In Python 3.7, the private re._pattern_type is removed.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be for PY37 then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typing.re was added in Python 3.5. I assume we want to use the officially documented way to check for regex pattern types.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry i only read the top comment. ok then.

if PY36:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a comment / pep ref here

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 """
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/dtypes/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down