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

(series == x) doesn't always produce a boolean series: bug? #933

Closed
xdong opened this issue Mar 17, 2012 · 2 comments

Comments

@xdong
Copy link

commented Mar 17, 2012

In [2]: a = pandas.Series(['a', nan, 'b'])

In [3]: a == 'a'
Out[3]:
0 True
1 NaN
2 False

There is a NaN in Out[3]. This can't be the desired result because of the following error:

In [4]: b = pandas.Series(['a', 'b', 'c'])

In [5]: (a == 'a') & (b == 'a')
ValueError Traceback (most recent call last)
/home/dong/ in ()
----> 1 (a == 'a') & (b == 'a')

/home/dong/.virtualenv/src/pandas/pandas/core/series.pyc in wrapper(self, other)
143 if isinstance(other, Series):
144 name = _maybe_match_name(self, other)
--> 145 return Series(na_op(self.values, other.values),
146 index=self.index, name=name)
147 elif isinstance(other, DataFrame):

/home/dong/.virtualenv/src/pandas/pandas/core/series.pyc in na_op(x, y)
132
133 if isinstance(y, np.ndarray):
--> 134 result = lib.vec_binop(x, y, op)
135 else:
136 result = lib.scalar_binop(x, y, op)

/home/dong/.virtualenv/src/pandas/pandas/_tseries.so in pandas._tseries.vec_binop (pandas/src/tseries.c:9302)()

ValueError: Does not understand character buffer dtype format string ('?')

BTW for series of dtype float there is no such problem:

In [6]: c = pandas.Series([1.0, nan, 3.0])

In [7]: c == 1
Out[7]:
0 True
1 False
2 False

@adamklein

This comment has been minimized.

Copy link
Contributor

commented Mar 22, 2012

Just a heads up that this is under consideration - thanks for bringing to attention.

@wesm

This comment has been minimized.

Copy link
Member

commented Apr 9, 2012

Looked at this again. Returning boolean array now (comparison with NA -> False)

@wesm wesm closed this Apr 9, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.