Skip to content

CLN: remove unnecessary _convert_index_indexer #36394

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 1 commit into from
Sep 17, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
17 changes: 1 addition & 16 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3252,7 +3252,7 @@ def _convert_listlike_indexer(self, keyarr):
Return tuple-safe keys.
"""
if isinstance(keyarr, Index):
keyarr = self._convert_index_indexer(keyarr)
pass
else:
keyarr = self._convert_arr_indexer(keyarr)
Comment on lines 3254 to 3257
Copy link
Member

Choose a reason for hiding this comment

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

This will probably be even cleaner:

if not isinstance(keyarr, Index):
    keyarr = self._convert_arr_indexer(keyarr)


Expand All @@ -3275,21 +3275,6 @@ def _convert_arr_indexer(self, keyarr):
keyarr = com.asarray_tuplesafe(keyarr)
return keyarr

def _convert_index_indexer(self, keyarr):
"""
Convert an Index indexer to the appropriate dtype.

Parameters
----------
keyarr : Index (or sub-class)
Indexer to convert.

Returns
-------
converted_keyarr : Index (or sub-class)
"""
return keyarr

def _convert_list_indexer(self, keyarr):
"""
Convert a list-like indexer to the appropriate dtype.
Expand Down
4 changes: 0 additions & 4 deletions pandas/core/indexes/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,10 +572,6 @@ def _convert_arr_indexer(self, keyarr):

return self._shallow_copy(keyarr)

@doc(Index._convert_index_indexer)
def _convert_index_indexer(self, keyarr):
return self._shallow_copy(keyarr)

@doc(Index._maybe_cast_slice_bound)
def _maybe_cast_slice_bound(self, label, side, kind):
if kind == "loc":
Expand Down
9 changes: 0 additions & 9 deletions pandas/core/indexes/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,15 +308,6 @@ def _convert_arr_indexer(self, keyarr):

return com.asarray_tuplesafe(keyarr, dtype=dtype)

@doc(Index._convert_index_indexer)
def _convert_index_indexer(self, keyarr):
# Cast the indexer to uint64 if possible so
# that the values returned from indexing are
# also uint64.
if keyarr.is_integer():
return keyarr.astype(np.uint64)
return keyarr

# ----------------------------------------------------------------

@classmethod
Expand Down
8 changes: 6 additions & 2 deletions pandas/tests/indexes/test_numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,11 @@ def test_range_float_union_dtype():
tm.assert_index_equal(result, expected)


def test_uint_index_does_not_convert_to_float64():
@pytest.mark.parametrize(
"box",
[list, lambda x: np.array(x, dtype=object), lambda x: pd.Index(x, dtype=object)],
)
def test_uint_index_does_not_convert_to_float64(box):
# https://github.com/pandas-dev/pandas/issues/28279
# https://github.com/pandas-dev/pandas/issues/28023
series = pd.Series(
Expand All @@ -646,7 +650,7 @@ def test_uint_index_does_not_convert_to_float64():
],
)

result = series.loc[[7606741985629028552, 17876870360202815256]]
result = series.loc[box([7606741985629028552, 17876870360202815256])]

expected = UInt64Index(
[7606741985629028552, 17876870360202815256, 17876870360202815256],
Expand Down