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 II #53120

Merged
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions pandas/tseries/frequencies.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from __future__ import annotations

from typing import TYPE_CHECKING
from typing import (
TYPE_CHECKING,
cast,
)

import numpy as np

Expand Down Expand Up @@ -51,6 +54,7 @@
Series,
TimedeltaIndex,
)
from pandas.core.arrays import TimedeltaArray
from pandas.core.arrays.datetimelike import DatetimeLikeArrayMixin
# ---------------------------------------------------------------------
# Offset names ("time rules") and related functions
Expand Down Expand Up @@ -172,15 +176,12 @@ def infer_freq(
inferer = _TimedeltaFrequencyInferer(index)
return inferer.get_freq()

if isinstance(index, Index) and not isinstance(index, DatetimeIndex):
elif isinstance(index, Index):
if is_numeric_dtype(index.dtype):
raise TypeError(
f"cannot infer freq from a non-convertible index of dtype {index.dtype}"
)
# error: Incompatible types in assignment (expression has type
# "Union[ExtensionArray, ndarray[Any, Any]]", variable has type
# "Union[DatetimeIndex, TimedeltaIndex, Series, DatetimeLikeArrayMixin]")
index = index._values # type: ignore[assignment]
index = cast("TimedeltaArray", 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.

this cant be right. TimedeltaIndex goes through the _TimedeltaFrequencyInferer path above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your comment. If I understand correctly, we only need to checkis_numeric_dtype(index.dtype)then.

Copy link
Member

Choose a reason for hiding this comment

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

yep, looks like that should work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thank you for reviewing this pr.


if not isinstance(index, DatetimeIndex):
index = DatetimeIndex(index)
Expand Down