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

TYP: remove ignore from pandas/tseries/frequencies.py #52623

Closed

Conversation

natmokval
Copy link
Contributor

Related to #37715
mypy ignore[assignment] was removed from pandas/tseries/frequencies.py

@mroeschke mroeschke added Frequency DateOffsets Typing type annotations, mypy/pyright type checking labels Apr 12, 2023
@natmokval natmokval marked this pull request as ready for review April 12, 2023 19:27
# "Union[ExtensionArray, ndarray[Any, Any]]", variable has type
# "Union[DatetimeIndex, TimedeltaIndex, Series, DatetimeLikeArrayMixin]")
index = index._values # type: ignore[assignment]
index = values
Copy link
Member

Choose a reason for hiding this comment

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

I'm surprised this works but I feel this might potentially hide bugs/inconsistencies in the type annotations. I think this mypy warning is "correct" given the type annotations.

I think this if statement could be if isinstance(index, TimedeltaIndex): If that is the case, TimedeltaIndex._values should be of type TimedeltaArray which is a sub-class of DatetimeLikeArrayMixin - meaning it wouldn't trigger this error. @jbrockmendel

If the above is the case, I think there are two ways to fix it:

  • simplify the if condition to if isinstance(index, TimedeltaIndex): and use index = cast(TimedeltaArray, index._values)
  • or better, annotate TimedeltaIndex._values as TimedeltaArray (and still change the if condition)

Copy link
Member

Choose a reason for hiding this comment

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

or better, annotate TimedeltaIndex._values as TimedeltaArray

seems reasonable

I think this if statement could be if isinstance(index, TimedeltaIndex)

No, TDI is specifically handled a few lines up in the elif is_timedelta64_dtype(index.dtype): section. Looks like this bit is for object dtype. though id be OK with deprecating allowing that here

@natmokval
Copy link
Contributor Author

@twoertwein, could you please take a look at my last changes? Looks like there are no failures in ci, but the last check Doc Build and Upload is still in progress for about 6 hours.

if isinstance(index, Index) and not isinstance(index, DatetimeIndex):
if not hasattr(index, "dtype"):
pass
elif isinstance(index.dtype, object):
Copy link
Member

Choose a reason for hiding this comment

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

I'm sorry, I'm not familiar enough with the code to review these code changes (more comfortable to review only type annotation changes)

@jbrockmendel
Copy link
Member

@natmokval can you merge main

@natmokval
Copy link
Contributor Author

@natmokval can you merge main

@jbrockmendel, I can merge main but these changes are in main already (see pr #53120). So I think it's better to close this pr. Sorry, I had to do it earlier.

@natmokval natmokval closed this May 25, 2023
@natmokval natmokval deleted the 37715-remove-mypy-ignore-V branch May 25, 2023 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Frequency DateOffsets Typing type annotations, mypy/pyright type checking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants