Skip to content

TYP: timestamps.pyi #40945

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 4 commits into from
Apr 26, 2021
Merged

Conversation

jbrockmendel
Copy link
Member

  • closes #xxxx
  • tests added / passed
  • Ensure all linting tests pass, see here for how to run them
  • whatsnew entry

@jreback jreback added this to the 1.3 milestone Apr 14, 2021
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.

lgtm @simonjayhawkins if comments

@jbrockmendel jbrockmendel added the Typing type annotations, mypy/pyright type checking label Apr 14, 2021
elif vtype is Timestamp:
# error: Non-overlapping identity check (left operand type: "Type[generic]",
# right operand type: "Type[Timestamp]")
elif vtype is Timestamp: # type: ignore[comparison-overlap]
Copy link
Member

Choose a reason for hiding this comment

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

There's a cast on L1895 that looks iffy. remove it and this ignore is not needed.

Copy link
Member

Choose a reason for hiding this comment

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

i've merged master locally so the line numbers differ.

else:
result = result.tz_localize(tz)
# error: Too many arguments for "tz_localize" of "NaTType"
result = result.tz_localize(tz) # type: ignore[call-arg]
Copy link
Member

Choose a reason for hiding this comment

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

if you update

    def tz_convert(self) -> NaTType: ...
    def tz_localize(self) -> NaTType: ...

in pandas/_libs/tslibs/nattype.pyi to match the signatures added here in pandas/_libs/tslibs/timestamps.pyi you could remove these ignores.

since these ignores appear to be false positives...

>>> pd.NaT.tz_convert("utc")
NaT
>>> 
>>> pd.NaT.tz_localize("Europe/London")
NaT

# error: Incompatible return value type (got "Union[Timestamp, NaTType,
# Series, Index]", expected "Union[DatetimeIndex, Series, float, str,
# NaTType, None]")
return result # type: ignore[return-value]
Copy link
Member

Choose a reason for hiding this comment

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

maybe use returns instead of assignment to result or change the type declaration of result to match the return type.

pd.Timedelta(days=42).asm8.view(
"datetime64[ns]"
) # type: ignore[arg-type]
),
Copy link
Member

Choose a reason for hiding this comment

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

This is a numpy issue. can't see an issue on github, maybe fixed in master. will check soon.

Timestamp(2000, 1, 2, 3, 4, 5, 6, 1, pytz.UTC),
# error: Argument 9 to "Timestamp" has incompatible type "_UTCclass";
# expected "Optional[int]"
Timestamp(2000, 1, 2, 3, 4, 5, 6, 1, pytz.UTC), # type: ignore[arg-type]
Copy link
Member

Choose a reason for hiding this comment

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

hmm, looks like will also need overloads for the constructor.

Copy link
Member

@simonjayhawkins simonjayhawkins left a comment

Choose a reason for hiding this comment

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

Thanks @jbrockmendel generally lgtm. happy to merge as is to add more types and work on the ignores as a follow-up.

@jbrockmendel
Copy link
Member Author

happy to merge as is to add more types and work on the ignores as a follow-up.

yah lets do as follow-ups if OK

@simonjayhawkins
Copy link
Member

yah lets do as follow-ups if OK

sure. have merged master

@simonjayhawkins simonjayhawkins merged commit 5faa34c into pandas-dev:master Apr 26, 2021
@simonjayhawkins
Copy link
Member

Thanks @jbrockmendel

@jbrockmendel jbrockmendel deleted the typ-timestamps branch April 26, 2021 17:18
yeshsurya pushed a commit to yeshsurya/pandas that referenced this pull request May 6, 2021
JulianWgs pushed a commit to JulianWgs/pandas that referenced this pull request Jul 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Typing type annotations, mypy/pyright type checking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants