Skip to content

Conversation

@TomAugspurger
Copy link
Contributor

Closes #20551

@TomAugspurger
Copy link
Contributor Author

TomAugspurger commented Mar 30, 2018

This is a bit slower. 3.6

In [3]: t1 = typing.re.Pattern

In [4]: t2 = type(re.compile(''))

In [5]: %timeit isinstance('', t1)
424 ns ± 8.76 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)

In [6]: %timeit isinstance('', t2)
99.5 ns ± 1.58 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)

3.7

In [1]: import re

In [2]: import typing

In [3]: t1 = typing.re.Pattern

In [4]: t2 = type(re.compile(''))

In [5]: %timeit isinstance('', t1)
741 ns ± 9.73 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)

In [6]: %timeit isinstance('', t2)
105 ns ± 1.62 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)

So just use type(re.compile('')) everywhere?

I think the timings are small enough, that I'd rather just use typing.re.Pattern since it's a bit clearer.

parse_date = _date_parser.parse


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

@jreback jreback added the Compat pandas objects compatability with Numpy or Python functions label Mar 30, 2018
@codecov
Copy link

codecov bot commented Mar 30, 2018

Codecov Report

Merging #20553 into master will increase coverage by 0.02%.
The diff coverage is 83.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #20553      +/-   ##
==========================================
+ Coverage   91.81%   91.83%   +0.02%     
==========================================
  Files         152      152              
  Lines       49259    49264       +5     
==========================================
+ Hits        45229    45244      +15     
+ Misses       4030     4020      -10
Flag Coverage Δ
#multiple 90.22% <83.33%> (+0.02%) ⬆️
#single 41.9% <83.33%> (ø) ⬆️
Impacted Files Coverage Δ
pandas/core/dtypes/inference.py 98.41% <100%> (ø) ⬆️
pandas/compat/__init__.py 58.43% <80%> (+0.69%) ⬆️
pandas/util/testing.py 84.52% <0%> (-0.21%) ⬇️
pandas/core/series.py 93.85% <0%> (ø) ⬆️
pandas/plotting/_converter.py 66.81% <0%> (+1.73%) ⬆️

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 c4b4a81...7681282. Read the comment docs.

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.

@jreback jreback added this to the 0.23.0 milestone Mar 30, 2018
@jreback
Copy link
Contributor

jreback commented Mar 30, 2018

lgtm.

@jreback
Copy link
Contributor

jreback commented Mar 31, 2018

thanks!

@jreback jreback merged commit 2eefe5a into pandas-dev:master Mar 31, 2018
kornilova203 pushed a commit to kornilova203/pandas that referenced this pull request Apr 23, 2018
@TomAugspurger TomAugspurger deleted the re-compat branch May 16, 2018 13:30
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants