Skip to content

BUG: Regresssion in handling of empty Series as indexers to Series (GH5877) #5880

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
Jan 8, 2014
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
1 change: 1 addition & 0 deletions doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ Bug Fixes
- Bug in isnull handling ``NaT`` in an object array (:issue:`5443`)
- Bug in ``to_datetime`` when passed a ``np.nan`` or integer datelike and a format string (:issue:`5863`)
- Bug in groupby dtype conversion with datetimelike (:issue:`5869`)
- Regresssion in handling of empty Series as indexers to Series (:issue:`5877`)

pandas 0.13.0
-------------
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1660,7 +1660,7 @@ def _is_bool_indexer(key):
if key.dtype == np.object_:
key = np.asarray(_values_from_object(key))

if len(key) and not lib.is_bool_array(key):
if not lib.is_bool_array(key):
if isnull(key).any():
raise ValueError('cannot index with vector containing '
'NA / NaN values')
Expand Down
23 changes: 23 additions & 0 deletions pandas/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from pandas import (Index, Series, DataFrame, isnull, notnull,
bdate_range, date_range, _np_version_under1p7)
from pandas.core.index import MultiIndex
from pandas.core.indexing import IndexingError
from pandas.tseries.index import Timestamp, DatetimeIndex
import pandas.core.config as cf
import pandas.lib as lib
Expand Down Expand Up @@ -795,6 +796,28 @@ def test_getitem_boolean_empty(self):
self.assertEqual(s.index.name, 'index_name')
self.assertEqual(s.dtype, np.int64)

# GH5877
# indexing with empty series
s = Series(['A', 'B'])
expected = Series(np.nan,index=['C'],dtype=object)
result = s[Series(['C'], dtype=object)]
assert_series_equal(result, expected)

s = Series(['A', 'B'])
expected = Series(dtype=object)
result = s[Series([], dtype=object)]
assert_series_equal(result, expected)

# invalid because of the boolean indexer
# that's empty or not-aligned
def f():
s[Series([], dtype=bool)]
self.assertRaises(IndexingError, f)

def f():
s[Series([True], dtype=bool)]
self.assertRaises(IndexingError, f)

def test_getitem_generator(self):
gen = (x > 0 for x in self.series)
result = self.series[gen]
Expand Down