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

fix: Series.dt argument 'ambiguous' can be boolean #1178

Conversation

cmp0xff
Copy link
Contributor

@cmp0xff cmp0xff commented Apr 3, 2025

Describe the bug

In the documentation and in practice, Series.dt.floor, Series.dt.round and Series.dt.ceil accept the argument ambiguous as boolean, which is however not supported in pandas-stubs.

To Reproduce

Provide a minimal runnable pandas example that is not properly checked by the stubs.

import pandas as pd

ts_series = pd.Series(pd.to_datetime(["2025-04-01 00:02+00"]))

ts_series.dt.floor(freq="min", ambiguous=False)

Indicate which type checker you are using (mypy or pyright).

mypy

Show the error message received from that type checker while checking your example.

dt_accessor.py:5:42: error: Argument "ambiguous" to "floor" of "_DatetimeRoundingMethods" has incompatible type "Literal[False]"; expected "Literal['raise', 'infer', 'NaT'] | ndarray[Any, dtype[bool_]]"  [arg-type]
Found 1 error in 1 file (checked 1 source file)

Please complete the following information:

OS: [e.g. Windows, Linux, MacOS]

Microsoft Windows 10 Enterprise

OS Version [e.g. 22]

10.0.19045 N/A Build 19045

python version

Python 3.13.2

version of type checker

mypy==1.15.0

version of installed pandas-stubs

pandas-stubs==2.2.3.250308

Additional context
Add any other context about the problem here.

@cmp0xff cmp0xff force-pushed the bugfix/cmp0xff/series-dt-accessor-ambiguous-argument branch 2 times, most recently from 26ac79e to a75cde3 Compare April 3, 2025 14:03
@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Apr 3, 2025

Thanks for the PR. The CI is failing because pyright is picking up that the import of sqlalchemy.ext.declarative is unnecessary in test_io.py , probably due to an update to pyright . Can you just delete that import, commit and push?

@cmp0xff cmp0xff force-pushed the bugfix/cmp0xff/series-dt-accessor-ambiguous-argument branch 2 times, most recently from bb23906 to 59c92b7 Compare April 3, 2025 16:25
Copy link
Collaborator

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

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

Instead of doing the __all__ thing, can you just pin pyright to 1.1.397 in pyproject.toml, because I just reported an issue here in pyright : microsoft/pyright#10248

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Apr 3, 2025

Also, can you not "force push" so then I can see what is changed with each commit more easily?

@cmp0xff cmp0xff force-pushed the bugfix/cmp0xff/series-dt-accessor-ambiguous-argument branch from 59c92b7 to 585c942 Compare April 3, 2025 16:31
@cmp0xff cmp0xff requested a review from Dr-Irv April 3, 2025 17:46
@cmp0xff
Copy link
Contributor Author

cmp0xff commented Apr 3, 2025

Hi @Dr-Irv , thank you for the review and input. I force-pushed because I wanted to keep the commits clean.

Copy link
Collaborator

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

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

Thanks @cmp0xff

@Dr-Irv Dr-Irv merged commit 59e8c0a into pandas-dev:main Apr 3, 2025
13 checks passed
@cmp0xff cmp0xff deleted the bugfix/cmp0xff/series-dt-accessor-ambiguous-argument branch April 3, 2025 18:59
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 this pull request may close these issues.

2 participants