Skip to content

CLN: misc cleanups #30877

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 8 commits into from
Jan 13, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
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
2 changes: 0 additions & 2 deletions pandas/_libs/index.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ cdef class IndexEngine:
"""
cdef:
object loc
void* data_ptr

loc = self.get_loc(key)
if isinstance(loc, slice) or util.is_array(loc):
Expand All @@ -101,7 +100,6 @@ cdef class IndexEngine:
"""
cdef:
object loc
void* data_ptr

loc = self.get_loc(key)
value = convert_scalar(arr, value)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -2279,7 +2279,7 @@ def _from_factorized(cls, uniques, original):
original.categories.take(uniques), dtype=original.dtype
)

def equals(self, other):
def equals(self, other) -> bool:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def equals(self, other) -> bool:
def equals(self, other: Any) -> bool:

Purely stylistic but we've been typing other as Any elsewhere, so good to do here as well (applicable in a few spots)

Copy link
Member Author

Choose a reason for hiding this comment

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

the docstring says other is Categorical; id prefer not to introduce mismatches

"""
Returns True if categorical arrays are equal.

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1347,7 +1347,7 @@ def _indexed_same(self, other) -> bool:
self._get_axis(a).equals(other._get_axis(a)) for a in self._AXIS_ORDERS
)

def equals(self, other):
def equals(self, other) -> bool_t:
"""
Test whether two objects contain the same elements.

Expand Down
16 changes: 5 additions & 11 deletions pandas/core/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,14 @@ def equals(self, other) -> bool:
return np.array_equal(self.asi8, other.asi8)

@Appender(_index_shared_docs["contains"] % _index_doc_kwargs)
def __contains__(self, key):
def __contains__(self, key) -> bool:
try:
res = self.get_loc(key)
return (
is_scalar(res)
or isinstance(res, slice)
or (is_list_like(res) and len(res))
)
except (KeyError, TypeError, ValueError):
return False
return bool(
Copy link
Contributor

Choose a reason for hiding this comment

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

isn't the bool redundant here?

Copy link
Member Author

Choose a reason for hiding this comment

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

not according to mypy

is_scalar(res) or isinstance(res, slice) or (is_list_like(res) and len(res))
)

# Try to run function on index first, and then on elements of index
# Especially important for group-by functionality
Expand Down Expand Up @@ -875,11 +873,7 @@ def _is_convertible_to_index_for_join(cls, other: Index) -> bool:

def _wrap_joined_index(self, joined, other):
name = get_op_result_name(self, other)
if (
isinstance(other, type(self))
and self.freq == other.freq
and self._can_fast_union(other)
):
if self._can_fast_union(other):
joined = self._shallow_copy(joined)
joined.name = name
return joined
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/range.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ def argsort(self, *args, **kwargs):
else:
return np.arange(len(self) - 1, -1, -1)

def equals(self, other):
def equals(self, other) -> bool:
"""
Determines if two Index objects contain the same elements.
"""
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1394,7 +1394,7 @@ def take(self, indexer, axis=1, verify=True, convert=True):
new_axis=new_labels, indexer=indexer, axis=axis, allow_dups=True
)

def equals(self, other):
def equals(self, other) -> bool:
self_axes, other_axes = self.axes, other.axes
if len(self_axes) != len(other_axes):
return False
Expand Down