Skip to content
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

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

Closed
jtratner opened this issue Sep 29, 2013 · 8 comments · Fixed by #28741
Closed

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

jtratner opened this issue Sep 29, 2013 · 8 comments · Fixed by #28741
Labels
API Design Dtype Conversions Unexpected or buggy dtype conversions Internals Related to non-user accessible pandas implementation
Milestone

Comments

@jtratner
Copy link
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__)

@jreback
Copy link
Contributor

jreback commented Sep 29, 2013

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
Copy link
Contributor Author

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

@jtratner
Copy link
Contributor Author

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
Copy link
Member

cpcloud commented Sep 29, 2013

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

@cpcloud
Copy link
Member

cpcloud commented Sep 29, 2013

so yes it's correct

@cpcloud
Copy link
Member

cpcloud commented Sep 29, 2013

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
Copy link
Contributor

jreback commented Sep 29, 2013

0.14 or 0.13?

@jtratner
Copy link
Contributor Author

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

@jreback jreback modified the milestones: 0.15.0, 0.14.0 Apr 6, 2014
@jreback jreback modified the milestones: 0.16.0, Next Major Release Mar 3, 2015
@jreback jreback modified the milestones: Contributions Welcome, 1.0 Oct 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Dtype Conversions Unexpected or buggy dtype conversions Internals Related to non-user accessible pandas implementation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants