Skip to content

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

Merged
merged 4 commits into from
Mar 22, 2021
Merged

TYP: nattype.pyi #40503

merged 4 commits into from
Mar 22, 2021

Conversation

jbrockmendel
Copy link
Member

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

@simonjayhawkins simonjayhawkins added the Typing type annotations, mypy/pyright type checking label Mar 19, 2021
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. just the code change for mypy is a concern. TimedeltaIndex.view(np.int64) and TimedeltaArray.view(np.int64) both return a numpy array.


def asm8(self) -> np.datetime64: ...
def to_datetime64(self) -> np.datetime64: ...
def to_numpy(self, dtype=..., copy: bool = False) -> np.datetime64: ...
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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]
Copy link
Member

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.

Copy link
Member Author

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.

@@ -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))
Copy link
Member

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.

@simonjayhawkins simonjayhawkins added this to the 1.3 milestone Mar 19, 2021
@jbrockmendel
Copy link
Member Author

updated + green

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 for the updates. have merged master to be sure.

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.

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]
Copy link
Contributor

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

@jreback jreback merged commit f841eda into pandas-dev:master Mar 22, 2021
@jbrockmendel jbrockmendel deleted the typ-nat branch March 22, 2021 14:30
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