-
-
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,35 @@ | ||||||
from datetime import tzinfo | ||||||
from typing import Optional | ||||||
|
||||||
import numpy as np | ||||||
|
||||||
from pandas import Timestamp | ||||||
|
||||||
def _test_parse_iso8601(ts: str) -> Timestamp: ... | ||||||
jbrockmendel marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
|
||||||
def format_array_from_datetime( | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. will add this to my list |
||||||
values: np.ndarray, # np.ndarray[np.int64] | ||||||
tz: Optional[tzinfo] = ..., | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
format: Optional[str] = ..., | ||||||
na_rep: object = ... | ||||||
) -> np.ndarray: ... # np.ndarray[object] | ||||||
|
||||||
|
||||||
def array_with_unit_to_datetime( | ||||||
values: np.ndarray, | ||||||
unit: str, | ||||||
errors: str = ..., | ||||||
) -> tuple[np.ndarray, Optional[tzinfo]]: ... | ||||||
|
||||||
|
||||||
def array_to_datetime( | ||||||
values: np.ndarray, # np.ndarray[object] | ||||||
errors: str = ..., | ||||||
dayfirst: bool = ..., | ||||||
yearfirst: bool = ..., | ||||||
utc: bool = ..., | ||||||
require_iso8601: bool = ..., | ||||||
allow_mixed: bool = ..., | ||||||
) -> tuple[np.ndarray, Optional[tzinfo]]: ... | ||||||
# returned ndarray may be object dtype or datetime64[ns] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2146,7 +2146,9 @@ def objects_to_datetime64ns( | |
require_iso8601=require_iso8601, | ||
allow_mixed=allow_mixed, | ||
) | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. added ignore not needed. order is inferred as i.e. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wont using Literal here cause problems? IIUC the There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. yep. This works.
and this fails
with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good call, updated |
||
except ValueError as err: | ||
try: | ||
values, tz_parsed = conversion.datetime_to_datetime64(data.ravel("K")) | ||
|
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