Skip to content

PERF: lazify type-check import #28342

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 2 commits into from
Sep 9, 2019
Merged
Changes from all 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
7 changes: 2 additions & 5 deletions pandas/io/formats/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import codecs
from contextlib import contextmanager
from datetime import tzinfo
import decimal
from functools import partial
from io import StringIO
Expand All @@ -27,8 +28,6 @@
)
from unicodedata import east_asian_width

from dateutil.tz.tz import tzutc
from dateutil.zoneinfo import tzfile
import numpy as np

from pandas._config.config import get_option, set_option
Expand Down Expand Up @@ -1552,9 +1551,7 @@ def _is_dates_only(


def _format_datetime64(
x: Union[NaTType, Timestamp],
tz: Optional[Union[tzfile, tzutc]] = None,
nat_rep: str = "NaT",
x: Union[NaTType, Timestamp], tz: Optional[tzinfo] = None, nat_rep: str = "NaT"
Copy link
Member

Choose a reason for hiding this comment

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

OK, so your determined not to remove!

in timestamps.pyx:

tz_convert: tz : str, pytz.timezone, dateutil.tz.tzfile or None

tz_localize: tz : str, pytz.timezone, dateutil.tz.tzfile or None

in tz_convert, tz on used in Timestamp constructor:

return Timestamp(self.value, tz=tz, freq=self.freq)

Timestamp: tz : str, pytz.timezone, dateutil.tz.tzfile or None

in tz_localize, tz used in Timestamp constructor and also:

maybe_get_tz(tz): (Maybe) Construct a timezone object from a string. If tz is a string, use
it to construct a timezone object. Otherwise, just return tz.

it'll be alot easier once the libs are annotated, mypy will do the checks for you.

Copy link
Member Author

Choose a reason for hiding this comment

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

I looked at removing, but it seemed weird to have the function have everything but that one thing annotated. I'll defer to you if you think removing is better.

Copy link
Member

Choose a reason for hiding this comment

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

because in testing, MonkeyType only saw "tzfile", "tzutc", then tzinfo is probably fine. it depends how the lib gets annotated, otherwise mypy will raise errors here if/when we add the stub and add the types.

strictly speaking this function could also take a string, but as used internally MonkeyType didn't see this function being called with that type.

i'm ok with tzinfo as it helps document the function for now.

) -> str:
if x is None or (is_scalar(x) and isna(x)):
return nat_rep
Expand Down