Skip to content

CLN: Assorted typings #28604

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 3 commits into from
Oct 1, 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
8 changes: 3 additions & 5 deletions pandas/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,14 @@ def _reconstruct_data(values, dtype, original):
-------
Index for extension types, otherwise ndarray casted to dtype
"""
from pandas import Index

if is_extension_array_dtype(dtype):
values = dtype.construct_array_type()._from_sequence(values)
elif is_bool_dtype(dtype):
values = values.astype(dtype)

# we only support object dtypes bool Index
if isinstance(original, Index):
if isinstance(original, ABCIndexClass):
values = values.astype(object)
elif dtype is not None:
values = values.astype(dtype)
Expand Down Expand Up @@ -833,7 +832,7 @@ def duplicated(values, keep="first"):
return f(values, keep=keep)


def mode(values, dropna=True):
def mode(values, dropna: bool = True):
"""
Returns the mode(s) of an array.

Expand Down Expand Up @@ -1888,7 +1887,7 @@ def searchsorted(arr, value, side="left", sorter=None):
}


def diff(arr, n, axis=0):
def diff(arr, n: int, axis: int = 0):
"""
difference of n between self,
analogous to s-s.shift(n)
Expand All @@ -1904,7 +1903,6 @@ def diff(arr, n, axis=0):
Returns
-------
shifted

"""

n = int(n)
Expand Down
16 changes: 10 additions & 6 deletions pandas/core/util/hashing.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
_default_hash_key = "0123456789123456"


def _combine_hash_arrays(arrays, num_items):
def _combine_hash_arrays(arrays, num_items: int):
"""
Parameters
----------
Expand Down Expand Up @@ -55,7 +55,11 @@ def _combine_hash_arrays(arrays, num_items):


def hash_pandas_object(
obj, index=True, encoding="utf8", hash_key=None, categorize=True
obj,
index: bool = True,
encoding: str = "utf8",
hash_key=None,
categorize: bool = True,
Copy link
Member

Choose a reason for hiding this comment

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

adding type hints here is causing pandas/core/util/hashing.py:132: error: Incompatible types in assignment (expression has type "chain[Any]", variable has type "Generator[Any, None, None]") further down as the body is now checked.

Copy link
Member

Choose a reason for hiding this comment

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

it looks like the conda environment now has mypy 0.720. result!

fix is here 304351e is you want to include in the PR. (can't use py3.6 variable annotations though.)

):
"""
Return a data hash of the Index/Series/DataFrame.
Expand Down Expand Up @@ -179,7 +183,7 @@ def hash_tuples(vals, encoding="utf8", hash_key=None):
return h


def hash_tuple(val, encoding="utf8", hash_key=None):
def hash_tuple(val, encoding: str = "utf8", hash_key=None):
"""
Hash a single tuple efficiently

Expand All @@ -201,7 +205,7 @@ def hash_tuple(val, encoding="utf8", hash_key=None):
return h


def _hash_categorical(c, encoding, hash_key):
def _hash_categorical(c, encoding: str, hash_key: str):
"""
Hash a Categorical by hashing its categories, and then mapping the codes
to the hashes
Expand Down Expand Up @@ -239,7 +243,7 @@ def _hash_categorical(c, encoding, hash_key):
return result


def hash_array(vals, encoding="utf8", hash_key=None, categorize=True):
def hash_array(vals, encoding: str = "utf8", hash_key=None, categorize: bool = True):
"""
Given a 1d array, return an array of deterministic integers.

Expand Down Expand Up @@ -317,7 +321,7 @@ def hash_array(vals, encoding="utf8", hash_key=None, categorize=True):
return vals


def _hash_scalar(val, encoding="utf8", hash_key=None):
def _hash_scalar(val, encoding: str = "utf8", hash_key=None):
"""
Hash scalar value

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/groupby/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ def test_categorical_no_compress():

def test_sort():

# http://stackoverflow.com/questions/23814368/sorting-pandas-categorical-labels-after-groupby # noqa: flake8
# http://stackoverflow.com/questions/23814368/sorting-pandas-categorical-labels-after-groupby # noqa: E501
# This should result in a properly sorted Series so that the plot
# has a sorted x axis
# self.cat.groupby(['value_group'])['value_group'].count().plot(kind='bar')
Expand Down