-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Removed ABCs from pandas._typing #27424
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
Changes from 3 commits
9c6e616
6490263
cce9afb
1fe6059
5f2fa6a
72d3e2c
c3bd6df
5a8d35a
5889715
ed2ee7f
095aed4
4bf254c
8f4a7a1
5e77b75
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,33 +1,35 @@ | ||||||
from pathlib import Path | ||||||
from typing import IO, AnyStr, TypeVar, Union | ||||||
from typing import IO, TYPE_CHECKING, AnyStr, TypeVar, Union | ||||||
|
||||||
import numpy as np | ||||||
|
||||||
from pandas._libs import Timestamp | ||||||
from pandas._libs.tslibs.period import Period | ||||||
from pandas._libs.tslibs.timedeltas import Timedelta | ||||||
if TYPE_CHECKING: # Use for any internal imports | ||||||
from pandas._libs import Timestamp | ||||||
from pandas._libs.tslibs.period import Period | ||||||
from pandas._libs.tslibs.timedeltas import Timedelta | ||||||
WillAyd marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
from pandas.core.arrays.base import ExtensionArray | ||||||
from pandas.core.dtypes.dtypes import ExtensionDtype | ||||||
from pandas.core.dtypes.generic import ( | ||||||
ABCDataFrame, | ||||||
ABCExtensionArray, | ||||||
ABCIndexClass, | ||||||
ABCSeries, | ||||||
ABCSparseSeries, | ||||||
WillAyd marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
) | ||||||
from pandas.core.indexes.base import Index | ||||||
from pandas.core.frame import DataFrame | ||||||
from pandas.core.series import Series | ||||||
from pandas.core.sparse.series import SparseSeries | ||||||
|
||||||
from pandas.core.dtypes.dtypes import ExtensionDtype | ||||||
from pandas.core.dtypes.generic import ( | ||||||
ABCDataFrame, | ||||||
ABCExtensionArray, | ||||||
ABCIndexClass, | ||||||
ABCSeries, | ||||||
ABCSparseSeries, | ||||||
) | ||||||
|
||||||
AnyArrayLike = TypeVar( | ||||||
"AnyArrayLike", | ||||||
ABCExtensionArray, | ||||||
ABCIndexClass, | ||||||
ABCSeries, | ||||||
ABCSparseSeries, | ||||||
np.ndarray, | ||||||
"AnyArrayLike", "ExtensionArray", "Index", "Series", "SparseSeries", np.ndarray | ||||||
) | ||||||
ArrayLike = TypeVar("ArrayLike", ABCExtensionArray, np.ndarray) | ||||||
DatetimeLikeScalar = TypeVar("DatetimeLikeScalar", Period, Timestamp, Timedelta) | ||||||
Dtype = Union[str, np.dtype, ExtensionDtype] | ||||||
ArrayLike = TypeVar("ArrayLike", "ExtensionArray", np.ndarray) | ||||||
DatetimeLikeScalar = TypeVar("DatetimeLikeScalar", "Period", "Timestamp", "Timedelta") | ||||||
Dtype = Union[str, np.dtype, "ExtensionDtype"] | ||||||
FilePathOrBuffer = Union[str, Path, IO[AnyStr]] | ||||||
|
||||||
FrameOrSeries = TypeVar("FrameOrSeries", ABCSeries, ABCDataFrame) | ||||||
FrameOrSeries = TypeVar("FrameOrSeries", "Series", "DataFrame") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
quote from https://mypy.readthedocs.io/en/latest/generics.html... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks but this just loosens the type system rather than actually fixing anything. TypeVar is going to be generally more useful for checking functions that can be fully generic in nature. Might just change the return of this one and see how many others require Union in the future There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. makes sense. Union[Series, DataFrame] might be better written as NDFrame anyway? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also the "user-defined generics" you are referring to are more applicable to containers not TypeVars. Right now we just use a blanket The TypeVar in the docs you linked is just a way of parametrizing that user-defined generic, so that a We are probably a ways off of doing user-defined generics but this is great that you looked into it. Certainly open to ideas on that front if you think of a good way to implement as we get more familiar with these annotations There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Hmm that would work though we don't typically import NDFrame anywhere so I don't think want to start here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would leave as FrameOrSeries as its more descriptive |
||||||
Scalar = Union[str, int, float] |
Uh oh!
There was an error while loading. Please reload this page.