Skip to content

Inconsistent comparisons between Series and 2-D ndarray #4615

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

Closed
cpcloud opened this issue Aug 20, 2013 · 9 comments
Closed

Inconsistent comparisons between Series and 2-D ndarray #4615

cpcloud opened this issue Aug 20, 2013 · 9 comments
Assignees
Labels
Bug Numeric Operations Arithmetic, Comparison, and Logical operations

Comments

@cpcloud
Copy link
Member

cpcloud commented Aug 20, 2013

related: #4585

In [5]: randn(10, 2) == Series(randn(2))
Out[5]:
array([[False, False],
       [False, False],
       [False, False],
       [False, False],
       [False, False],
       [False, False],
       [False, False],
       [False, False],
       [False, False],
       [False, False]], dtype=bool)

but

In [6]: randn(10, 2) <= Series(randn(2))

throws an Exception.

got a PR in the works

@ghost ghost assigned cpcloud Aug 20, 2013
@jreback
Copy link
Contributor

jreback commented Aug 20, 2013

maybe just do in top of #4585?

@jreback
Copy link
Contributor

jreback commented Sep 22, 2013

@jtratner you might need to add this as a case in your ops refactor....

@jtratner
Copy link
Contributor

Is this just because of the lack of an __rle__ method?

@jreback
Copy link
Contributor

jreback commented Sep 22, 2013

since one doesn't exist currently could be

@jtratner
Copy link
Contributor

In 0.12.0 they both raise a ValueError (same one):

ValueError                                Traceback (most recent call last)
<ipython-input-9-ca6a5964cdf5> in <module>()
----> 1 randn(10, 2) <= Series(randn(2))

/usr/local/lib/python2.7/site-packages/pandas/core/series.pyc in wrapper(self, other)
    224         elif isinstance(other, pa.Array):
    225             if len(self) != len(other):
--> 226                 raise ValueError('Lengths must match to compare')
    227             return Series(na_op(self.values, np.asarray(other)),
    228                           index=self.index, name=self.name)
ValueError: Lengths must match to compare

In current master, one (probably) works correctly [randn(10, 2) == Series(randn(2))], but the other one raises this exception:

Exception                                 Traceback (most recent call last)
<ipython-input-8-ca6a5964cdf5> in <module>()
----> 1 randn(10, 2) <= Series(randn(2))

../pandas/pandas/core/series.pyc in __array_wrap__(self, result)
    789         """
    790         return self._constructor(result, index=self.index, name=self.name,
--> 791                                  copy=False)
    792
    793     def __contains__(self, key):

../pandas/pandas/core/series.pyc in __init__(self, data, index, dtype, name, copy, fastpath)
    655             else:
    656                 data = _sanitize_array(data, index, dtype, copy,
--> 657                                        raise_cast_failure=True)
    658
    659                 data = SingleBlockManager(data, index, fastpath=True)

../pandas/pandas/core/series.pyc in _sanitize_array(data, index, dtype, copy, raise_cast_failure)
   3307     elif subarr.ndim > 1:
   3308         if isinstance(data, pa.Array):
-> 3309             raise Exception('Data must be 1-dimensional')
   3310         else:
   3311             subarr = _asarray_tuplesafe(data, dtype=dtype)

@jreback
Copy link
Contributor

jreback commented Sep 23, 2013

numpy prob let's these go thru, but we have to stop these....

In [5]: Series(range(2)) == np.arange(20).reshape(2,10)
Out[5]: 
0    False
1    False
dtype: bool

@cpcloud
Copy link
Member Author

cpcloud commented Sep 28, 2013

pushing this to first thing in 0.14

@jbrockmendel
Copy link
Member

In master (and 0.23.3) neither of the operations in the OP work; both raise with "Lengths must match to compare".

Is this something we want to support?

@jbrockmendel jbrockmendel assigned cpcloud and jbrockmendel and unassigned cpcloud Jan 28, 2019
@mroeschke
Copy link
Member

I think we've tightened up comparison ops with pandas object to ensure similar shape a while back to be more strict and not as flexible as this. Going to close but happy to reopen if there's more interest for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Numeric Operations Arithmetic, Comparison, and Logical operations
Projects
None yet
Development

No branches or pull requests

5 participants