Skip to content

TYPING: Module 'pytz' has no attribute 'FixedOffset' #28932

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

Closed
Closed
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
27 changes: 15 additions & 12 deletions pandas/tests/indexes/datetimes/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
from datetime import datetime, time
import locale

# https://github.com/python/typeshed/pull/XXXX
# error: Module 'pytz' has no attribute 'FixedOffset'
Copy link
Member Author

Choose a reason for hiding this comment

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

this is annoying. isort doesn't keep the comment next to the ignore

Copy link
Member

Choose a reason for hiding this comment

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

Should we try to fix upstream in isort?

from dateutil.parser import parse
from dateutil.tz.tz import tzoffset
import numpy as np
import pytest
import pytz
from pytz import FixedOffset # type:ignore

from pandas._libs import tslib
from pandas._libs.tslibs import iNaT, parsing
Expand Down Expand Up @@ -267,29 +270,29 @@ def test_to_datetime_format_weeks(self, cache):
[
"%Y-%m-%d %H:%M:%S%z",
["2010-01-01 12:00:00+0100"] * 2,
[pd.Timestamp("2010-01-01 12:00:00", tzinfo=pytz.FixedOffset(60))] * 2,
[pd.Timestamp("2010-01-01 12:00:00", tzinfo=FixedOffset(60))] * 2,
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 you just pytz.FixedOffset to avoid the issues above?

Copy link
Member Author

Choose a reason for hiding this comment

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

was just trying to use 1 ignore instead of 8..

$ mypy pandas
pandas\tests\indexes\datetimes\test_tools.py:270: error: Module has no attribute "FixedOffset"
pandas\tests\indexes\datetimes\test_tools.py:275: error: Module has no attribute "FixedOffset"
pandas\tests\indexes\datetimes\test_tools.py:281: error: Module has no attribute "FixedOffset"
pandas\tests\indexes\datetimes\test_tools.py:282: error: Module has no attribute "FixedOffset"
pandas\tests\indexes\datetimes\test_tools.py:290: error: Module has no attribute "FixedOffset"
pandas\tests\indexes\datetimes\test_tools.py:292: error: Module has no attribute "FixedOffset"
pandas\tests\indexes\datetimes\test_tools.py:2082: error: Module has no attribute "FixedOffset"
pandas\tests\indexes\datetimes\test_tools.py:2087: error: Module has no attribute "FixedOffset"
Found 8 errors in 1 file (checked 805 source files)

],
[
"%Y-%m-%d %H:%M:%S %z",
["2010-01-01 12:00:00 +0100"] * 2,
[pd.Timestamp("2010-01-01 12:00:00", tzinfo=pytz.FixedOffset(60))] * 2,
[pd.Timestamp("2010-01-01 12:00:00", tzinfo=FixedOffset(60))] * 2,
],
[
"%Y-%m-%d %H:%M:%S %z",
["2010-01-01 12:00:00 +0100", "2010-01-01 12:00:00 -0100"],
[
pd.Timestamp("2010-01-01 12:00:00", tzinfo=pytz.FixedOffset(60)),
pd.Timestamp("2010-01-01 12:00:00", tzinfo=pytz.FixedOffset(-60)),
pd.Timestamp("2010-01-01 12:00:00", tzinfo=FixedOffset(60)),
pd.Timestamp("2010-01-01 12:00:00", tzinfo=FixedOffset(-60)),
],
],
[
"%Y-%m-%d %H:%M:%S %z",
["2010-01-01 12:00:00 Z", "2010-01-01 12:00:00 Z"],
[
pd.Timestamp(
"2010-01-01 12:00:00", tzinfo=pytz.FixedOffset(0)
), # pytz coerces to UTC
pd.Timestamp("2010-01-01 12:00:00", tzinfo=pytz.FixedOffset(0)),
"2010-01-01 12:00:00", tzinfo=FixedOffset(0)
), # pytz.FixedOffset coerces to UTC
pd.Timestamp("2010-01-01 12:00:00", tzinfo=FixedOffset(0)),
],
],
],
Expand Down Expand Up @@ -931,8 +934,8 @@ def test_iso_8601_strings_same_offset_no_box(self):

expected = np.array(
[
datetime(2018, 1, 4, 9, 1, tzinfo=pytz.FixedOffset(540)),
datetime(2018, 1, 4, 9, 2, tzinfo=pytz.FixedOffset(540)),
datetime(2018, 1, 4, 9, 1, tzinfo=FixedOffset(540)),
datetime(2018, 1, 4, 9, 2, tzinfo=FixedOffset(540)),
],
dtype=object,
)
Expand Down Expand Up @@ -1006,7 +1009,7 @@ def test_mixed_offsets_with_native_datetime_raises(self):
def test_non_iso_strings_with_tz_offset(self):
result = to_datetime(["March 1, 2018 12:00:00+0400"] * 2)
expected = DatetimeIndex(
[datetime(2018, 3, 1, 12, tzinfo=pytz.FixedOffset(240))] * 2
[datetime(2018, 3, 1, 12, tzinfo=FixedOffset(240))] * 2
)
tm.assert_index_equal(result, expected)

Expand Down Expand Up @@ -2079,12 +2082,12 @@ def test_parsers_time(self):
[
(
"2013-01-01 05:45+0545",
pytz.FixedOffset(345),
FixedOffset(345),
"Timestamp('2013-01-01 05:45:00+0545', tz='pytz.FixedOffset(345)')",
),
(
"2013-01-01 05:30+0530",
pytz.FixedOffset(330),
FixedOffset(330),
"Timestamp('2013-01-01 05:30:00+0530', tz='pytz.FixedOffset(330)')",
),
],
Expand Down