Skip to content

Commit fb2bb58

Browse files
committed
BUG: Make sure series-series boolean comparions are label based (GH4947)
1 parent 6f96d7d commit fb2bb58

File tree

3 files changed

+64
-7
lines changed

3 files changed

+64
-7
lines changed

doc/source/release.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,8 @@ Bug Fixes
374374
- appending a 0-len table will work correctly (:issue:`4273`)
375375
- ``to_hdf`` was raising when passing both arguments ``append`` and ``table`` (:issue:`4584`)
376376
- reading from a store with duplicate columns across dtypes would raise (:issue:`4767`)
377+
- Fixed a bug where ``ValueError`` wasn't correctly raised when column names
378+
weren't strings (:issue:`4956`)
377379
- Fixed bug in tslib.tz_convert(vals, tz1, tz2): it could raise IndexError exception while
378380
trying to access trans[pos + 1] (:issue:`4496`)
379381
- The ``by`` argument now works correctly with the ``layout`` argument
@@ -500,8 +502,6 @@ Bug Fixes
500502
- Fixed a bug with setting invalid or out-of-range values in indexing
501503
enlargement scenarios (:issue:`4940`)
502504
- Tests for fillna on empty Series (:issue:`4346`), thanks @immerrr
503-
- Fixed a bug where ``ValueError`` wasn't correctly raised when column names
504-
weren't strings (:issue:`4956`)
505505
- Fixed ``copy()`` to shallow copy axes/indices as well and thereby keep
506506
separate metadata. (:issue:`4202`, :issue:`4830`)
507507
- Fixed skiprows option in Python parser for read_csv (:issue:`4382`)
@@ -521,6 +521,7 @@ Bug Fixes
521521
- Fix a bug where reshaping a ``Series`` to its own shape raised ``TypeError`` (:issue:`4554`)
522522
and other reshaping issues.
523523
- Bug in setting with ``ix/loc`` and a mixed int/string index (:issue:`4544`)
524+
- Make sure series-series boolean comparions are label based (:issue:`4947`)
524525

525526
pandas 0.12.0
526527
-------------

pandas/tests/test_frame.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4523,8 +4523,10 @@ def f():
45234523
def test_logical_with_nas(self):
45244524
d = DataFrame({'a': [np.nan, False], 'b': [True, True]})
45254525

4526+
# GH4947
4527+
# bool comparisons should return bool
45264528
result = d['a'] | d['b']
4527-
expected = Series([np.nan, True])
4529+
expected = Series([True, True])
45284530
assert_series_equal(result, expected)
45294531

45304532
# GH4604, automatic casting here
@@ -4533,10 +4535,6 @@ def test_logical_with_nas(self):
45334535
assert_series_equal(result, expected)
45344536

45354537
result = d['a'].fillna(False,downcast=False) | d['b']
4536-
expected = Series([True, True],dtype=object)
4537-
assert_series_equal(result, expected)
4538-
4539-
result = (d['a'].fillna(False,downcast=False) | d['b']).convert_objects()
45404538
expected = Series([True, True])
45414539
assert_series_equal(result, expected)
45424540

pandas/tests/test_series.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2757,6 +2757,64 @@ def test_comparison_different_length(self):
27572757
b = Series([2, 3, 4])
27582758
self.assertRaises(ValueError, a.__eq__, b)
27592759

2760+
def test_comparison_label_based(self):
2761+
2762+
# GH 4947
2763+
# comparisons should be label based
2764+
2765+
a = Series([True, False, True], list('bca'))
2766+
b = Series([False, True, False], list('abc'))
2767+
2768+
expected = Series([True, False, False], list('bca'))
2769+
result = a & b
2770+
assert_series_equal(result,expected)
2771+
2772+
expected = Series([True, False, True], list('bca'))
2773+
result = a | b
2774+
assert_series_equal(result,expected)
2775+
2776+
expected = Series([False, False, True], list('bca'))
2777+
result = a ^ b
2778+
assert_series_equal(result,expected)
2779+
2780+
# rhs is bigger
2781+
a = Series([True, False, True], list('bca'))
2782+
b = Series([False, True, False, True], list('abcd'))
2783+
2784+
expected = Series([True, False, False], list('bca'))
2785+
result = a & b
2786+
assert_series_equal(result,expected)
2787+
2788+
expected = Series([True, False, True], list('bca'))
2789+
result = a | b
2790+
assert_series_equal(result,expected)
2791+
2792+
# filling
2793+
2794+
# vs empty
2795+
result = a & Series([])
2796+
expected = Series([False, False, False], list('bca'))
2797+
assert_series_equal(result,expected)
2798+
2799+
result = a | Series([])
2800+
expected = Series([True, True, True], list('bca'))
2801+
assert_series_equal(result,expected)
2802+
2803+
# vs non-matching
2804+
result = a & Series([1],['z'])
2805+
expected = Series([False, False, False], list('bca'))
2806+
assert_series_equal(result,expected)
2807+
2808+
result = a | Series([1],['z'])
2809+
expected = Series([True, True, True], list('bca'))
2810+
assert_series_equal(result,expected)
2811+
2812+
# identity
2813+
# we would like s[s|e] == s to hold for any e, whether empty or not
2814+
for e in [Series([]),Series([1],['z']),Series(['z']),Series(np.nan,b.index),Series(np.nan,a.index)]:
2815+
result = a[a | e]
2816+
assert_series_equal(result,a)
2817+
27602818
def test_between(self):
27612819
s = Series(bdate_range('1/1/2000', periods=20).asobject)
27622820
s[::2] = np.nan

0 commit comments

Comments
 (0)