Skip to content

BUG: GH10645 and GH10692 where operation on large Index would error #11049

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 10, 2015
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
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.17.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ Bug Fixes
- Bug in ``Index.take`` may add unnecessary ``freq`` attribute (:issue:`10791`)
- Bug in ``merge`` with empty ``DataFrame`` may raise ``IndexError`` (:issue:`10824`)
- Bug in ``to_latex`` where unexpected keyword argument for some documented arguments (:issue:`10888`)

- Bug in indexing of large ``DataFrame`` where ``IndexError`` is uncaught (:issue:`10645` and :issue:`10692`)
- Bug in ``read_csv`` when using the ``nrows`` or ``chunksize`` parameters if file contains only a header line (:issue:`9535`)
- Bug in serialization of ``category`` types in HDF5 in presence of alternate encodings. (:issue:`10366`)
- Bug in ``pd.DataFrame`` when constructing an empty DataFrame with a string dtype (:issue:`9428`)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -4727,7 +4727,7 @@ def __contains__(self, key):
try:
self.get_loc(key)
return True
except KeyError:
except LookupError:
return False

def __reduce__(self):
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ def _convert_to_indexer(self, obj, axis=0, is_setter=False):
# if we are a label return me
try:
return labels.get_loc(obj)
except KeyError:
except LookupError:
if isinstance(obj, tuple) and isinstance(labels, MultiIndex):
if is_setter and len(obj) == labels.nlevels:
return {'key': obj}
Expand Down Expand Up @@ -1125,7 +1125,7 @@ def _convert_to_indexer(self, obj, axis=0, is_setter=False):
else:
try:
return labels.get_loc(obj)
except KeyError:
except LookupError:
# allow a not found key only if we are a setter
if not is_list_like_indexer(obj) and is_setter:
return {'key': obj}
Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4602,7 +4602,17 @@ def test_indexing_dtypes_on_empty(self):
assert_series_equal(df2.loc[:,'a'], df2.iloc[:,0])
assert_series_equal(df2.loc[:,'a'], df2.ix[:,0])

def test_large_dataframe_indexing(self):
#GH10692
result = DataFrame({'x': range(10**6)})
result.loc[len(result)] = len(result) + 1
expected = DataFrame({'x': range(10**6 + 1)})
assert_frame_equal(result, expected)

def test_large_mi_dataframe_indexing(self):
#GH10645
result = MultiIndex.from_arrays([range(10**6), range(10**6)])
assert(not (10**6, 0) in result)
Copy link
Contributor

Choose a reason for hiding this comment

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

use self.assertFalse(....)


class TestCategoricalIndex(tm.TestCase):

Expand Down