-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
PERF: lazify pytz seqToRE call, trims 35ms from import #28228
Conversation
How does the init impact import time? Are we instantiating these at import? |
Yes, there is an instance of this in the module namespace. |
if key == "Z": | ||
# lazy computation | ||
if self._Z is None: | ||
self._Z = self.__seqToRE(pytz.all_timezones, 'Z') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
slightly OT this should be a module level function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the seqRE i mean
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is based on a class vendored from the stdlib, so probably not
lgtm to me |
Thanks @jbrockmendel |
@WillAyd IIRC you made the top-level Panel import lazy in py37. have you looked at e.g. https://pypi.org/project/modutil/ for doing this in more places? top-level imports from pandas.io.api look like the next place we can trim |
Haven't looked a lot at lazy imports, so if you have concrete proposals certainly put them out there. Just keep in mind as one downside to lazy imports I think you would lose type checking against those libraries, since that import I don't think can be resolved statically |
Shaves on the order of 5% off of import time.
Unrelated docstring fixups, improve typing on parse_timezone_directive and _calc_julian_from_V.
The important thing here is setting the "Z" key dynamically in
__getitem__
instead of in__init__
(since an instance is created in the module namespace at importt)