Skip to content

BUG: type aliasing is not allowed to be compared using isinstance() #21098

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
May 17, 2018

Conversation

adamabk
Copy link
Contributor

@adamabk adamabk commented May 17, 2018

As raised in #21078, Python 3.5.4 supports the using isinstance() with typing.re.Pattern But it does not support the same method in 3.5.2.

Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> import typing
>>> isinstance(re.compile(''), typing.re.Pattern)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.5/typing.py", line 260, in __instancecheck__
    raise TypeError("Type aliases cannot be used with isinstance().")
TypeError: Type aliases cannot be used with isinstance().

This Bugfix PR is to revert the re_type to be back to what it used to be before the update with the new release.

@WillAyd
Copy link
Member

WillAyd commented May 17, 2018

Thanks for the PR. Reading through the issue I think the suggestion was to only use the old way for 3.5.2 and older, but should keep it for newer versions.

You'd be better off just changing the original condition to if sys.version_info >= (3,5,3) (or 3.5.4 - whichever is applicable)

@codecov
Copy link

codecov bot commented May 17, 2018

Codecov Report

Merging #21098 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #21098   +/-   ##
=======================================
  Coverage   91.83%   91.83%           
=======================================
  Files         153      153           
  Lines       49497    49497           
=======================================
  Hits        45456    45456           
  Misses       4041     4041
Flag Coverage Δ
#multiple 90.23% <100%> (ø) ⬆️
#single 41.88% <100%> (ø) ⬆️
Impacted Files Coverage Δ
pandas/compat/__init__.py 58.43% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d623ffd...278e67e. Read the comment docs.

@adamabk adamabk force-pushed the bug_str_replace branch from 9eaee7b to 783af28 Compare May 17, 2018 04:47
@adamabk
Copy link
Contributor Author

adamabk commented May 17, 2018

That makes a lot more sense.

I only changed the PY35 so thatthe re_type = typing.re.Pattern is only applicable for 3.5.4 or above.

@WillAyd
Copy link
Member

WillAyd commented May 17, 2018

No I wouldn’t do that - that item is used many other places in the package so there are a lot of implications there. I meant just change the original conditional that you removed

@adamabk
Copy link
Contributor Author

adamabk commented May 17, 2018

Noob mistake! I just made sure that the conditional statement is only applicable when sys.version_info is 3.5.4 or above.

@jreback jreback added this to the 0.23.1 milestone May 17, 2018
@jreback jreback added the Compat pandas objects compatability with Numpy or Python functions label May 17, 2018
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

can you add your example as a test

@@ -425,7 +425,7 @@ def raise_with_traceback(exc, traceback=Ellipsis):

# In Python 3.7, the private re._pattern_type is removed.
# Python 3.5+ have typing.re.Pattern
Copy link
Contributor

Choose a reason for hiding this comment

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

why don't we just make this >= PY36 and call it a day?

@jreback
Copy link
Contributor

jreback commented May 17, 2018

also pls add a note in the whatsnew (0.23.1) add a strings sub-section in bug fixes

@jreback jreback added the Strings String extension data type and string data label May 17, 2018
@adamabk adamabk force-pushed the bug_str_replace branch from d098f99 to 89adc7d Compare May 17, 2018 14:14
@adamabk adamabk force-pushed the bug_str_replace branch from 89adc7d to e2a6ea0 Compare May 17, 2018 14:17


def test_re_type():
import re
Copy link
Contributor

Choose a reason for hiding this comment

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

can u move the import to the top

@adamabk
Copy link
Contributor Author

adamabk commented May 17, 2018

Should do the trick. Thanks for the guidance!

@TomAugspurger TomAugspurger merged commit 6cc5f23 into pandas-dev:master May 17, 2018
@TomAugspurger
Copy link
Contributor

Thanks for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Compat pandas objects compatability with Numpy or Python functions Strings String extension data type and string data
Projects
None yet
Development

Successfully merging this pull request may close these issues.

.replace() raises when replacing strings
4 participants