-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
TYP: simple return types #54786
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
Merged
Merged
TYP: simple return types #54786
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6bf9293
Return None
twoertwein f1fb1ea
Return simple types
twoertwein f64da4b
ruff false positive
twoertwein 54c05c4
isort+mypy
twoertwein d23a54b
typo, use " for cast
twoertwein eeddfa8
SingleArrayManager.dtype can also be a numpy dtype
twoertwein 3213488
comments + test assert on CI
twoertwein bdb2d07
wider return types at the cost of one fewer mypy ignore
twoertwein 4c7baf6
Merge remote-tracking branch 'upstream/main' into type
twoertwein 5139ed3
DatetimeArray reaches IntervalArray._combined
twoertwein 1a82367
avoid some ignores
twoertwein 954b275
remove assert False
twoertwein File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,7 +110,7 @@ | |
) | ||
|
||
|
||
IntervalSideT = Union[TimeArrayLike, np.ndarray] | ||
IntervalSide = Union[TimeArrayLike, np.ndarray] | ||
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. ...T is often used for TypeVars |
||
IntervalOrNA = Union[Interval, float] | ||
|
||
_interval_shared_docs: dict[str, str] = {} | ||
|
@@ -219,8 +219,8 @@ def ndim(self) -> Literal[1]: | |
return 1 | ||
|
||
# To make mypy recognize the fields | ||
_left: IntervalSideT | ||
_right: IntervalSideT | ||
_left: IntervalSide | ||
_right: IntervalSide | ||
_dtype: IntervalDtype | ||
|
||
# --------------------------------------------------------------------- | ||
|
@@ -237,8 +237,8 @@ def __new__( | |
data = extract_array(data, extract_numpy=True) | ||
|
||
if isinstance(data, cls): | ||
left: IntervalSideT = data._left | ||
right: IntervalSideT = data._right | ||
left: IntervalSide = data._left | ||
right: IntervalSide = data._right | ||
closed = closed or data.closed | ||
dtype = IntervalDtype(left.dtype, closed=closed) | ||
else: | ||
|
@@ -280,8 +280,8 @@ def __new__( | |
@classmethod | ||
def _simple_new( | ||
cls, | ||
left: IntervalSideT, | ||
right: IntervalSideT, | ||
left: IntervalSide, | ||
right: IntervalSide, | ||
dtype: IntervalDtype, | ||
) -> Self: | ||
result = IntervalMixin.__new__(cls) | ||
|
@@ -299,7 +299,7 @@ def _ensure_simple_new_inputs( | |
closed: IntervalClosedType | None = None, | ||
copy: bool = False, | ||
dtype: Dtype | None = None, | ||
) -> tuple[IntervalSideT, IntervalSideT, IntervalDtype]: | ||
) -> tuple[IntervalSide, IntervalSide, IntervalDtype]: | ||
"""Ensure correctness of input parameters for cls._simple_new.""" | ||
from pandas.core.indexes.base import ensure_index | ||
|
||
|
@@ -1031,8 +1031,8 @@ def _concat_same_type(cls, to_concat: Sequence[IntervalArray]) -> Self: | |
raise ValueError("Intervals must all be closed on the same side.") | ||
closed = closed_set.pop() | ||
|
||
left = np.concatenate([interval.left for interval in to_concat]) | ||
right = np.concatenate([interval.right for interval in to_concat]) | ||
left: IntervalSide = np.concatenate([interval.left for interval in to_concat]) | ||
right: IntervalSide = np.concatenate([interval.right for interval in to_concat]) | ||
|
||
left, right, dtype = cls._ensure_simple_new_inputs(left, right, closed=closed) | ||
|
||
|
@@ -1283,7 +1283,7 @@ def _format_space(self) -> str: | |
# Vectorized Interval Properties/Attributes | ||
|
||
@property | ||
def left(self): | ||
def left(self) -> Index: | ||
""" | ||
Return the left endpoints of each Interval in the IntervalArray as an Index. | ||
|
||
|
@@ -1303,7 +1303,7 @@ def left(self): | |
return Index(self._left, copy=False) | ||
|
||
@property | ||
def right(self): | ||
def right(self) -> Index: | ||
""" | ||
Return the right endpoints of each Interval in the IntervalArray as an Index. | ||
|
||
|
@@ -1855,11 +1855,17 @@ def isin(self, values) -> npt.NDArray[np.bool_]: | |
return isin(self.astype(object), values.astype(object)) | ||
|
||
@property | ||
def _combined(self) -> IntervalSideT: | ||
left = self.left._values.reshape(-1, 1) | ||
right = self.right._values.reshape(-1, 1) | ||
def _combined(self) -> IntervalSide: | ||
# error: Item "ExtensionArray" of "ExtensionArray | ndarray[Any, Any]" | ||
# has no attribute "reshape" [union-attr] | ||
left = self.left._values.reshape(-1, 1) # type: ignore[union-attr] | ||
right = self.right._values.reshape(-1, 1) # type: ignore[union-attr] | ||
rhshadrach marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if needs_i8_conversion(left.dtype): | ||
comb = left._concat_same_type([left, right], axis=1) | ||
# error: Item "ndarray[Any, Any]" of "Any | ndarray[Any, Any]" has | ||
# no attribute "_concat_same_type" | ||
comb = left._concat_same_type( # type: ignore[union-attr] | ||
[left, right], axis=1 | ||
) | ||
else: | ||
comb = np.concatenate([left, right], axis=1) | ||
return comb | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.