Skip to content
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

pd.to_datetime(list[datetime.date]) is wrong input type (mypy), but pandas returns output. #891

Closed
vanheck opened this issue Mar 19, 2024 · 2 comments · Fixed by #892
Closed
Labels
datetime.date stdlib datetime.date support good first issue

Comments

@vanheck
Copy link
Contributor

vanheck commented Mar 19, 2024

Describe the bug
datetime.date is a valid type as a function parameter, but mypy raises errors

To Reproduce

test.py file:

from datetime import date
import pandas as pd

dates = [date.today(), date.today()]
dates = pd.to_datetime(dates)

in dates is DatetimeIndex(['2024-03-19', '2024-03-19'], dtype='datetime64[ns]', freq=None)

But mypy returns:

# mypy test.py
test.py:5: error: Incompatible types in assignment (expression has type "DatetimeIndex", variable has type "list[date]")  [assignment]
test.py:5: error: Argument 1 to "to_datetime" has incompatible type "list[date]"; expected "Sequence[float | datetime] | list[str] | tuple[float | str | datetime, ...] | ndarray[Any, dtype[datetime64]] | ndarray[Any, dtype[str_]] | ndarray[Any, dtype[signedinteger[Any]]] | Index[Any] | ExtensionArray"  [arg-type]
Found 2 errors in 1 file (checked 1 source file)

Please complete the following information:

  • OS: Linux Ubuntu 22.04.4 LTS x86_64
  • python version 3.10.13
  • version of type checker: mypy 1.7.1 (compiled: yes)
  • version of installed pandas-stubs: 2.2.0.240218
  • pandas 2.2.1
@vanheck vanheck changed the title pd.to_datetime(list[datetime.date]) is wrong input, but pandas returns output. pd.to_datetime(list[datetime.date]) is wrong input (mypy), but pandas returns output. Mar 19, 2024
@vanheck vanheck changed the title pd.to_datetime(list[datetime.date]) is wrong input (mypy), but pandas returns output. pd.to_datetime(list[datetime.date]) is wrong input type (mypy), but pandas returns output. Mar 19, 2024
@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Mar 19, 2024

Thanks for the report.

Need to change datetime to date in this line:

Sequence[float | datetime]

and 2 lines below that, since datetime is a subclass of date

PR welcome with tests in test_pandas.py

@Dr-Irv Dr-Irv added good first issue datetime.date stdlib datetime.date support labels Mar 19, 2024
vanheck added a commit to vanheck/pandas-stubs that referenced this issue Mar 19, 2024
@vanheck
Copy link
Contributor Author

vanheck commented Mar 19, 2024

Challange accepted, there is #892

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
datetime.date stdlib datetime.date support good first issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants