Skip to content

BUG: bool methods are wrong with DataFrame and Series (or at least wrong error) #5035

Closed
@jtratner

Description

@jtratner
Contributor
from pandas import Series, DataFrame
s = Series([2, 3, 4, 5, 6, 7, 8, 9, 10])
d = DataFrame({'a': s})
s + d
d + s
print(d & s)

produces Traceback:

raceback (most recent call last):
  File "testcase2.py", line 6, in <module>
    print(d & s)
  File "../pandas/core/frame.py", line 217, in f
    return self._combine_series(other, na_op, fill_value, axis, level)
  File "../pandas/core/frame.py", line 3040, in _combine_series
    return self._combine_match_columns(other, func, fill_value)
  File "../pandas/core/frame.py", line 3079, in _combine_match_columns
    func, right, axes=[left.columns, self.index])
  File "../pandas/core/internals.py", line 2048, in eval
    return self.apply('eval', *args, **kwargs)
  File "../pandas/core/internals.py", line 2033, in apply
    applied = getattr(blk, f)(*args, **kwargs)
  File "../pandas/core/internals.py", line 850, in eval
    result = get_result(other)
  File "../pandas/core/internals.py", line 834, in get_result
    return self._try_coerce_result(func(values, other))
  File "../pandas/core/frame.py", line 201, in na_op
    mask = notnull(xrav) & notnull(yrav)
ValueError: operands could not be broadcast together with shapes (81) (9)

s & d currently raises NotImplemented instead. (because there's no __rand__)

Activity

jreback

jreback commented on Sep 29, 2013

@jreback
Contributor

I don't think this implemented per se, may have to manually broadcast the operands (the numeric ops might do this, not sure why bool not)

jtratner

jtratner commented on Sep 29, 2013

@jtratner
ContributorAuthor

It's weird, bool and numeric use the same _arith_method too.

jtratner

jtratner commented on Sep 29, 2013

@jtratner
ContributorAuthor

Similarly, how about this, is this right?

In [2]: from pandas import *

In [3]: ser = Series(range(10))

In [4]: df = DataFrame({'a': ser})

In [6]: df + ser
Out[6]:
    0   1   2   3   4   5   6   7   8   9   a
0 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
1 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
2 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
3 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
4 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
5 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
6 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
7 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
8 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
9 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
cpcloud

cpcloud commented on Sep 29, 2013

@cpcloud
Member

it aligns on the oclumns by default, and ser doesn't have a in its index

cpcloud

cpcloud commented on Sep 29, 2013

@cpcloud
Member

so yes it's correct

cpcloud

cpcloud commented on Sep 29, 2013

@cpcloud
Member

to align on the index u have to do:

In [13]: df.add(ser,axis=0)
Out[13]:
    a
0   0
1   2
2   4
3   6
4   8
5  10
6  12
7  14
8  16
9  18
jreback

jreback commented on Sep 29, 2013

@jreback
Contributor

0.14 or 0.13?

jtratner

jtratner commented on Sep 29, 2013

@jtratner
ContributorAuthor

well, it's long-standing, so probably fine to push to 0.14.

modified the milestones: 0.15.0, 0.14.0 on Apr 6, 2014
modified the milestones: 0.16.0, Next Major Release on Mar 3, 2015
modified the milestones: Contributions Welcome, 1.0 on Oct 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    API DesignDtype ConversionsUnexpected or buggy dtype conversionsInternalsRelated to non-user accessible pandas implementation

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      Participants

      @cpcloud@jreback@jtratner

      Issue actions

        BUG: bool methods are wrong with DataFrame and Series (or at least wrong error) · Issue #5035 · pandas-dev/pandas