Skip to content

mypy error when passing np.datetime64 or np.timedelta64 to pd.isna #549

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

Closed
nph opened this issue Feb 21, 2023 · 1 comment · Fixed by #550
Closed

mypy error when passing np.datetime64 or np.timedelta64 to pd.isna #549

nph opened this issue Feb 21, 2023 · 1 comment · Fixed by #550

Comments

@nph
Copy link
Contributor

nph commented Feb 21, 2023

Describe the bug
pd.isna does not support np.datetime64 and np.timedelta64 input types.

To Reproduce

from __future__ import annotations

import datetime as dt
from typing import TypeVar

import numpy as np
import pandas as pd

TV_TD = TypeVar('TV_TD', dt.datetime, np.datetime64, dt.timedelta, np.timedelta64)

def test_isna(value: TV_TD) -> bool:
    return pd.isna(value)

mypy output:

 error: No overload variant of "isna" matches argument type "datetime64"  [call-overload]
 note: Possible overload variants:
 note:     def isna(obj: DataFrame) -> DataFrame
 note:     def isna(obj: Series[Any]) -> Series[bool]
 note:     def isna(obj: Union[Index, List[Any], Union[ExtensionArray, ndarray[Any, Any]]]) -> ndarray[Any, dtype[bool_]]
 note:     def isna(obj: Union[Union[Union[str, bytes, date, datetime, timedelta, bool, int, float, Timestamp, Timedelta], complex], NaTType, NAType, None]) -> TypeGuard[Union[NaTType, NAType, None]]
 error: No overload variant of "isna" matches argument type "timedelta64"  [call-overload]
Found 2 errors in 1 file (checked 1 source file)

Please complete the following information:

  • OS: MacOS
  • OS 12.6.3
  • python: 3.8.0
  • mypy: 1.0.1
  • version of installed pandas-stubs: 1.5.3.230214

Additional context
The problem seems to be that the IndexIterScalar TypeAlias does not include np.datetime64 and np.timedelta64. The test_isna test case is also missing tests for np.datetime64 and np.timedelta64 input. PR with a fix here

nph added a commit to intervaliq/pandas-stubs that referenced this issue Feb 21, 2023
…64` (pandas-dev#549)

* Fixes mypy error when passing np.datetime64/timedelta64 input to pd.isna

* Update test_isna to include tests for np.datetime64/timedelta64
@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Feb 21, 2023

The problem seems to be that the IndexIterScalar TypeAlias does not include np.datetime64 and np.timedelta64. The test_isna test case is also missing tests for np.datetime64 and np.timedelta64 input. I'll submit a PR with a fix.

Yes, that is correct. Hopefully just adding those 2 types to IndexIterScalar will do the trick and not break anything else. Make sure to include tests.

Dr-Irv pushed a commit that referenced this issue Feb 21, 2023
…d.isna` (#550)

Update `IndexIterScalar` to include `np.datetime64` and `np.timedelta64` (#549)

* Fixes mypy error when passing np.datetime64/timedelta64 input to pd.isna

* Update test_isna to include tests for np.datetime64/timedelta64
twoertwein pushed a commit to twoertwein/pandas-stubs that referenced this issue Apr 1, 2023
…d.isna` (pandas-dev#550)

Update `IndexIterScalar` to include `np.datetime64` and `np.timedelta64` (pandas-dev#549)

* Fixes mypy error when passing np.datetime64/timedelta64 input to pd.isna

* Update test_isna to include tests for np.datetime64/timedelta64
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants