8000 #25790 Updating type hints to Python3 syntax in pandas/core/array by gwrome · Pull Request #25829 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

#25790 Updating type hints to Python3 syntax in pandas/core/array #25829

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 16 commits into from
Mar 30, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Change remaining forward refs to ABCs
  • Loading branch information
gwrome committed Mar 28, 2019
commit 33db1eef3c3361cebe61b439ba15af4569ce6ade
12 changes: 6 additions & 6 deletions pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ def shift(
self,
periods: int = 1,
fill_value: object = None,
) -> 'ExtensionArray':
) -> ABCExtensionArray:
"""
Shift values by desired number.

Expand Down Expand Up @@ -621,7 +621,7 @@ def _values_for_factorize(self) -> Tuple[np.ndarray, Any]:
def factorize(
self,
na_sentinel: int = -1,
) -> Tuple[np.ndarray, 'ExtensionArray']:
) -> Tuple[np.ndarray, ABCExtensionArray]:
"""
Encode the extension array as an enumerated type.

Expand Down Expand Up @@ -728,7 +728,7 @@ def take(
indices: Sequence[int],
allow_fill: bool = False,
fill_value: Any = None
) -> 'ExtensionArray':
) -> ABCExtensionArray:
"""
Take elements from an array.

Expand Down Expand Up @@ -817,7 +817,7 @@ def take(self, indices, allow_fill=False, fill_value=None):
# pandas.api.extensions.take
raise AbstractMethodError(self)

def copy(self, deep: bool = False) -> 'ExtensionArray':
def copy(self, deep: bool = False) -> ABCExtensionArray:
"""
Return a copy of the array.

Expand Down Expand Up @@ -901,8 +901,8 @@ def _formatting_values(self) -> np.ndarray:
@classmethod
def _concat_same_type(
cls,
to_concat: Sequence['ExtensionArray']
) -> 'ExtensionArray':
to_concat: Sequence[ABCExtensionArray]
) -> ABCExtensionArray:
"""
Concatenate multiple array

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ def _addsub_int_array(
self,
other: Union[ExtensionArray, np.ndarray, ABCIndexClass],
Copy link
Member

Choose a reason for hiding this comment

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

Any reason for removing the type for ndarray?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

During my testing at the time (before you added mypy.ini and the rest of the type checking framework to the project), mypy was throwing an error that suggested that ndarrays couldn't take a subscript, so I dropped it. I probably had something in my testing environment set up incorrectly (or maybe more strictly, not sure), because it doesn't throw that error with the current mypy.ini minus the blacklist. Will add it back.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wait, it wasn't mypy. code_checks doctests throws

...pandas/core/arrays/period.py", line 545, in PeriodArray
    other: Union[ExtensionArray, np.ndarray[int], ABCIndexClass],
TypeError: 'type' object is not subscriptable

Copy link
Member

Choose a reason for hiding this comment

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

Gotcha. Kind of strange this throws an error now but not before. Something to revisit later

op: Callable[[Any], Any]
) -> 'PeriodArray':
) -> ABCPeriodArray:
assert op in [operator.add, operator.sub]
if op is operator.sub:
other = -other
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/arrays/sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ def _subtype_with_str(self):
_sparray_doc_kwargs = dict(klass='SparseArray')


def _get_fill(arr: 'SparseArray') -> np.ndarray:
def _get_fill(arr: ABCSparseArray) -> np.ndarray:
"""
Create a 0-dim ndarray containing the fill value

Expand Down Expand Up @@ -680,7 +680,7 @@ def _simple_new(
sparse_array: np.ndarray,
sparse_index: SparseIndex,
dtype: SparseDtype
) -> 'SparseArray':
) -> ABCSparseArray:
new = cls([])
new._sparse_index = sparse_index
new._sparse_values = sparse_array
Expand Down
0