-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TYP: mostly core.arrays, some core.indexes #40545
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
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
647a393
DOC: suppress warnings from CategoricalBlock deprecation
jbrockmendel 8b8d6a2
Merge branch 'master' into ci-doc
jbrockmendel d348888
TYP: annotate all the things
jbrockmendel ffde5a4
typo fixup
jbrockmendel 284d995
Merge branch 'master' into typ-indexes
jbrockmendel 6f28c56
Merge branch 'ci-doc' into typ-indexes
jbrockmendel 36ff42f
Merge branch 'master' into typ-indexes
jbrockmendel 80b53c1
annotate PandasArray axis kwargs
jbrockmendel 5af47b9
Merge branch 'master' into typ-indexes
jbrockmendel 267b34b
mypy fixup
jbrockmendel 95c0b9d
Merge branch 'master' into typ-indexes
jbrockmendel 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -327,7 +327,7 @@ def _format_native_types(self, na_rep="NaT", date_format=None): | |
""" | ||
raise AbstractMethodError(self) | ||
|
||
def _formatter(self, boxed=False): | ||
def _formatter(self, boxed: bool = False): | ||
# TODO: Remove Datetime & DatetimeTZ formatters. | ||
return "'{}'".format | ||
|
||
|
@@ -354,7 +354,7 @@ def __getitem__( | |
result._freq = self._get_getitem_freq(key) | ||
return result | ||
|
||
def _get_getitem_freq(self, key): | ||
def _get_getitem_freq(self, key) -> Optional[BaseOffset]: | ||
""" | ||
Find the `freq` attribute to assign to the result of a __getitem__ lookup. | ||
""" | ||
|
@@ -406,7 +406,7 @@ def _maybe_clear_freq(self): | |
# DatetimeArray and TimedeltaArray | ||
pass | ||
|
||
def astype(self, dtype, copy=True): | ||
def astype(self, dtype, copy: bool = True): | ||
# Some notes on cases we don't have to handle here in the base class: | ||
# 1. PeriodArray.astype handles period -> period | ||
# 2. DatetimeArray.astype handles conversion between tz. | ||
|
@@ -545,7 +545,7 @@ def _values_for_factorize(self): | |
|
||
@classmethod | ||
def _from_factorized( | ||
cls: Type[DatetimeLikeArrayT], values, original | ||
cls: Type[DatetimeLikeArrayT], values, original: DatetimeLikeArrayT | ||
) -> DatetimeLikeArrayT: | ||
return cls(values, dtype=original.dtype) | ||
|
||
|
@@ -939,7 +939,7 @@ def freq(self, value): | |
self._freq = value | ||
|
||
@property | ||
def freqstr(self): | ||
def freqstr(self) -> Optional[str]: | ||
""" | ||
Return the frequency object as a string if its set, otherwise None. | ||
""" | ||
|
@@ -948,7 +948,7 @@ def freqstr(self): | |
return self.freq.freqstr | ||
|
||
@property # NB: override with cache_readonly in immutable subclasses | ||
def inferred_freq(self): | ||
def inferred_freq(self) -> Optional[str]: | ||
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. don't we have a Freq typing? 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. we do, but this is more specific |
||
""" | ||
Tries to return a string representing a frequency guess, | ||
generated by infer_freq. Returns None if it can't autodetect the | ||
|
@@ -963,8 +963,11 @@ def inferred_freq(self): | |
|
||
@property # NB: override with cache_readonly in immutable subclasses | ||
def _resolution_obj(self) -> Optional[Resolution]: | ||
freqstr = self.freqstr | ||
if freqstr is None: | ||
return None | ||
try: | ||
return Resolution.get_reso_from_freq(self.freqstr) | ||
return Resolution.get_reso_from_freq(freqstr) | ||
except KeyError: | ||
return None | ||
|
||
|
@@ -1241,7 +1244,7 @@ def _addsub_object_array(self, other: np.ndarray, op): | |
) | ||
return result | ||
|
||
def _time_shift(self, periods, freq=None): | ||
def _time_shift(self, periods: int, freq=None): | ||
""" | ||
Shift each value by `periods`. | ||
|
@@ -1440,7 +1443,7 @@ def __isub__(self, other): | |
# -------------------------------------------------------------- | ||
# Reductions | ||
|
||
def min(self, *, axis=None, skipna=True, **kwargs): | ||
def min(self, *, axis: Optional[int] = None, skipna: bool = True, **kwargs): | ||
jreback marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
Return the minimum value of the Array or minimum along | ||
an axis. | ||
|
@@ -1469,7 +1472,7 @@ def min(self, *, axis=None, skipna=True, **kwargs): | |
result = nanops.nanmin(self._ndarray, axis=axis, skipna=skipna) | ||
return self._wrap_reduction_result(axis, result) | ||
|
||
def max(self, *, axis=None, skipna=True, **kwargs): | ||
def max(self, *, axis: Optional[int] = None, skipna: bool = True, **kwargs): | ||
""" | ||
Return the maximum value of the Array or maximum along | ||
an axis. | ||
|
@@ -1500,7 +1503,7 @@ def max(self, *, axis=None, skipna=True, **kwargs): | |
result = nanops.nanmax(self._ndarray, axis=axis, skipna=skipna) | ||
return self._wrap_reduction_result(axis, result) | ||
|
||
def mean(self, *, skipna=True, axis: Optional[int] = 0): | ||
def mean(self, *, skipna: bool = True, axis: Optional[int] = 0): | ||
""" | ||
Return the mean value of the Array. | ||
|
@@ -1568,7 +1571,7 @@ class DatelikeOps(DatetimeLikeArrayMixin): | |
URL="https://docs.python.org/3/library/datetime.html" | ||
"#strftime-and-strptime-behavior" | ||
) | ||
def strftime(self, date_format): | ||
def strftime(self, date_format: str) -> np.ndarray: | ||
""" | ||
Convert to Index using specified date_format. | ||
|
@@ -1760,7 +1763,7 @@ def all(self, *, axis: Optional[int] = None, skipna: bool = True): | |
# -------------------------------------------------------------- | ||
# Frequency Methods | ||
|
||
def _maybe_clear_freq(self): | ||
def _maybe_clear_freq(self) -> None: | ||
self._freq = None | ||
|
||
def _with_freq(self, freq): | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should be consistent about this pattern, IIRC we use
Dict[str, int]
? cc @simonjayhawkins ok either way, we should have a rule and convertThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC there was no objection to using the new syntax, just not ready to convert all existing annotations yet. I recall a discussion about this and I _think_the outcome was that we would wait till closer to 1.3 to use pyupgrade to reduce the potential conflicts with backports but I can't find the relevant discussion. @MarcoGorelli
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was #39930
Removing
--keep-runtime-typing
will upgrade to newer syntax in files withfrom __future__ import annotations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahh yes. it was because mypy in 1.2.x is on an older version. #39538 (review)
nbd. can fixup the backports if necessary to use the older syntax. so imo can do whenever.