-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
TYP: nattype.pyi #40503
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: nattype.pyi #40503
Conversation
jbrockmendel
commented
Mar 18, 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. just the code change for mypy is a concern. TimedeltaIndex.view(np.int64)
and TimedeltaArray.view(np.int64)
both return a numpy array.
pandas/_libs/tslibs/nattype.pyi
Outdated
|
||
def asm8(self) -> np.datetime64: ... | ||
def to_datetime64(self) -> np.datetime64: ... | ||
def to_numpy(self, dtype=..., copy: bool = False) -> np.datetime64: ... |
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.
def to_numpy(self, dtype=..., copy: bool = False) -> np.datetime64: ... | |
def to_numpy(self, dtype=..., copy: bool = ...) -> np.datetime64: ... |
@@ -202,7 +202,8 @@ def _get_cell_value(self, cell, convert_float: bool) -> Scalar: | |||
elif cell_type == "time": | |||
result = pd.to_datetime(str(cell)) | |||
result = cast(pd.Timestamp, result) | |||
return result.time() | |||
# error: Item "str" of "Union[float, str, NaTType]" has no attribute "time" | |||
return result.time() # type: ignore[union-attr] |
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.
observation. pd.Timestamp
resolves to Any
, so cast above has no effect.
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.
yah, Timestamp is pretty much going to be left for last in this process. Among other things, mypy complains about __new__
sometimes returning NaT.
pandas/io/formats/format.py
Outdated
@@ -1796,17 +1799,13 @@ def get_format_timedelta64( | |||
|
|||
If box, then show the return in quotes | |||
""" | |||
values_int = values.view(np.int64) | |||
values_int = np.asarray(values.view(np.int64)) |
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 you shouldn't need to do this. once the overloads for view are more comprehensive, mypy will know that .view(np.int64)
returns an numpy array.
I would leave this unchanged for now.
updated + green |
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 for the updates. have merged master to be sure.
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.
minor comment for followup
# error: Incompatible types in assignment (expression has type | ||
# "Union[DatetimeLikeArrayMixin, Union[Any, NaTType]]", variable has | ||
# type "Union[ExtensionArray, ndarray]") | ||
dta = dta[0] # type: ignore[assignment] |
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.
if you return you can avoid this i think