-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
TYP: tslib.pyi #40473
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
TYP: tslib.pyi #40473
Conversation
jbrockmendel
commented
Mar 16, 2021
- closes #xxxx
- tests added / passed
- Ensure all linting tests pass, see here for how to run them
- whatsnew entry
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.
Thanks @jbrockmendel generally lgtm.
def _test_parse_iso8601(ts: str) -> Timestamp: ... | ||
|
||
|
||
def format_array_from_datetime( |
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.
OT: ravel_compat decorator is not typed to preserve function signatures. so the types added here wouldn't be propagated when consistency checking
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.
will add this to my list
pandas/_libs/tslib.pyi
Outdated
|
||
def format_array_from_datetime( | ||
values: np.ndarray, # np.ndarray[np.int64] | ||
tz: Optional[tzinfo] = ..., |
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.
tz: Optional[tzinfo] = ..., | |
tz: tzinfo | None = ..., |
pandas/_libs/tslib.pyi
Outdated
|
||
import numpy as np | ||
|
||
from pandas import Timestamp |
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.
OT: we will need to add checks to make sure that these imports don't resolve to Any
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.
yep. this ended up getting remove when i took out _test_parse_iso8601
pandas/core/arrays/datetimes.py
Outdated
result = result.reshape(data.shape, order=order) | ||
# error: No overload variant of "reshape" of "_ArrayOrScalarCommon" | ||
# matches argument types "Tuple[int, ...]", "str" | ||
result = result.reshape(data.shape, order=order) # type: ignore[call-overload] |
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.
added ignore not needed. order is inferred as str
by mypy. can override the mypy inference with a variable type annotation.
i.e. order: Literal["F", "C"] = "F" if flags.f_contiguous else "C"
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.
wont using Literal here cause problems? IIUC the __future__
import makes Literal OK i function annotations, but not variable annotations
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 variable annotations (inside functions) aren't parsed by the Python interpreter even without the __future__ import, but will need to confirm this.
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.
yep. This works.
def func():
a: Unknown
print("Success!")
func()
and this fails
a: Unknown
print("Success!")
with NameError: name 'Unknown' is not defined
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.
good call, updated
Thanks @jbrockmendel |