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: Logical operator of Series with Index (#22092) #22293

Merged
merged 9 commits into from
Sep 18, 2018

Conversation

makbigc
Copy link
Contributor

@makbigc makbigc commented Aug 12, 2018

@gfyoung gfyoung added Bug Dtype Conversions Unexpected or buggy dtype conversions Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff labels Aug 13, 2018
@@ -497,6 +497,6 @@ Other
- :meth: `~pandas.io.formats.style.Styler.background_gradient` now takes a ``text_color_threshold`` parameter to automatically lighten the text color based on the luminance of the background color. This improves readability with dark background colors without the need to limit the background colormap range. (:issue:`21258`)
- Require at least 0.28.2 version of ``cython`` to support read-only memoryviews (:issue:`21688`)
- :meth: `~pandas.io.formats.style.Styler.background_gradient` now also supports tablewise application (in addition to rowwise and columnwise) with ``axis=None`` (:issue:`15204`)
-
- Bug in the logical operator of :class:`Series` with :class:`Index` (:issue:`22092`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps something like:

Bug in logical operators handling :class:`Series` and :class:`Index` together (:issue:`22092`)

@jreback jreback requested a review from jbrockmendel August 13, 2018 11:42
@codecov
Copy link

codecov bot commented Aug 13, 2018

Codecov Report

Merging #22293 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #22293   +/-   ##
=======================================
  Coverage   92.16%   92.16%           
=======================================
  Files         169      169           
  Lines       50708    50708           
=======================================
  Hits        46734    46734           
  Misses       3974     3974
Flag Coverage Δ
#multiple 90.57% <100%> (ø) ⬆️
#single 42.35% <0%> (ø) ⬆️
Impacted Files Coverage Δ
pandas/core/ops.py 96.94% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 996f361...aaf8349. Read the comment docs.

@@ -497,6 +497,6 @@ Other
- :meth: `~pandas.io.formats.style.Styler.background_gradient` now takes a ``text_color_threshold`` parameter to automatically lighten the text color based on the luminance of the background color. This improves readability with dark background colors without the need to limit the background colormap range. (:issue:`21258`)
- Require at least 0.28.2 version of ``cython`` to support read-only memoryviews (:issue:`21688`)
- :meth: `~pandas.io.formats.style.Styler.background_gradient` now also supports tablewise application (in addition to rowwise and columnwise) with ``axis=None`` (:issue:`15204`)
-
- Bug in the logical operators handling :class:`Series` and :class:`Index` together (:issue:`22092`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Describe the bug briefly. For an example, see #22173.

@@ -1383,7 +1383,7 @@ def na_op(x, y):
if isinstance(y, list):
y = construct_1d_object_array_from_listlike(y)

if isinstance(y, (np.ndarray, ABCSeries)):
if isinstance(y, (np.ndarray, ABCSeries, ABCIndex)):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be ABCIndexClass, not ABCIndex.

Copy link
Member

@jbrockmendel jbrockmendel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test looks good, some comments on the whatsnew and the edit in core.ops. I'm partial to #22173 for this, but not exactly unbiased there.

@@ -537,6 +537,23 @@ def test_comparison_flex_alignment_fill(self):
exp = pd.Series([True, True, False, False], index=list('abcd'))
assert_series_equal(left.gt(right, fill_value=0), exp)

def test_comparison_with_index(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you check this on Int64Index as well. I think some other index types might work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"comparison" is a misnomer here. Consider "binary_ops" or "logical_ops"

idx = Index([True, False, True, False])

expected = Series([True, False, False, False])
result = ser & idx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @jbrockmendel I think we DO allow this on index types which don't makes sense, but we DO raise on Series, e.g.

not sure what to make of [1] and [2]

In [1]: dti = pd.date_range('20130101', periods=3)

In [2]: dti ^ dti
Out[2]: DatetimeIndex([], dtype='datetime64[ns]', freq=None)

In [3]: dti & dti
Out[3]: DatetimeIndex(['2013-01-01', '2013-01-02', '2013-01-03'], dtype='datetime64[ns]', freq='D')
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

# I think this PR fixes this one?
In [4]: pd.Series(dti) & dti

# this is good
In [5]: pd.Series(dti) & pd.Series(dti)
TypeError: cannot astype a datetimelike from [datetime64[ns]] to [bool]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we DO allow this on index types which don't makes sense, but we DO raise on Series,

Yah I've opened a couple of Issues about this. The existing Series ops don't handle dt64/td64 at all, and are not super-clear for some other dtypes. The reversed op(Index, Series) ops are a separate can of worms because those are set operations.

I don't think this PR fixes [4] (yet), needs to chance ABCIndex to ABCIndexClass (like #22173)

Copy link
Contributor

@jreback jreback Aug 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok this is fine then (for now as you have other issues about this)

@makbigc
Copy link
Contributor Author

makbigc commented Aug 14, 2018

Changing from ABCIndex to ACBIndexClass, it can handle Int64Index too. Thanks for your advice. @jbrockmendel

The tests on Int64Index are also added. @jreback

@makbigc
Copy link
Contributor Author

makbigc commented Aug 20, 2018

@jreback @jbrockmendel Would you tell me if there is anything to be implemented? Or failing one of the tests does matter?

@@ -497,6 +497,6 @@ Other
- :meth: `~pandas.io.formats.style.Styler.background_gradient` now takes a ``text_color_threshold`` parameter to automatically lighten the text color based on the luminance of the background color. This improves readability with dark background colors without the need to limit the background colormap range. (:issue:`21258`)
- Require at least 0.28.2 version of ``cython`` to support read-only memoryviews (:issue:`21688`)
- :meth: `~pandas.io.formats.style.Styler.background_gradient` now also supports tablewise application (in addition to rowwise and columnwise) with ``axis=None`` (:issue:`15204`)
-
- Logical operation ``&, |, ^`` between :class:`Series` and :class:`Index` will no longer raise ``ValueError`` (:issue:`22092`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: pls make "operation" plural

@jbrockmendel
Copy link
Member

Pending minor comments, LGTM.

@jreback jreback added this to the 0.24.0 milestone Aug 22, 2018
@makbigc
Copy link
Contributor Author

makbigc commented Aug 22, 2018

Changed. Thanks for your reply

@makbigc
Copy link
Contributor Author

makbigc commented Aug 27, 2018

ping @jreback Could this be merged?

@makbigc
Copy link
Contributor Author

makbigc commented Sep 4, 2018

ping @jreback @jbrockmendel Is there anything to be implemented before this PR can be merged?

@jbrockmendel
Copy link
Member

Is there anything to be implemented before this PR can be merged?

@makbigc I can't speak for jreback, but rebasing will definitely be necessary

@pep8speaks
Copy link

Hello @makbigc! Thanks for updating the PR.

@makbigc
Copy link
Contributor Author

makbigc commented Sep 10, 2018

@jreback do you anything else to be implemented? Please tell me.

@jreback
Copy link
Contributor

jreback commented Sep 15, 2018

looks good, can you rebase, ping on green.

@makbigc
Copy link
Contributor Author

makbigc commented Sep 17, 2018

@jreback changed. No conflict right now.

Copy link
Member

@gfyoung gfyoung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job!

@jreback
Copy link
Contributor

jreback commented Sep 18, 2018

lgtm. @jbrockmendel over to you

@jreback
Copy link
Contributor

jreback commented Sep 18, 2018

@jbrockmendel ok if ok, pls approve and merge

@jbrockmendel jbrockmendel merged commit 4e0b636 into pandas-dev:master Sep 18, 2018
aeltanawy pushed a commit to aeltanawy/pandas that referenced this pull request Sep 20, 2018
…-dev#22293)

* Fix bug #GH22092

* Update v0.24.0.txt

* Update v0.24.0.txt

* Update ops.py

* Update test_operators.py

* Update v0.24.0.txt

* Update test_operators.py
Sup3rGeo pushed a commit to Sup3rGeo/pandas that referenced this pull request Oct 1, 2018
…-dev#22293)

* Fix bug #GH22092

* Update v0.24.0.txt

* Update v0.24.0.txt

* Update ops.py

* Update test_operators.py

* Update v0.24.0.txt

* Update test_operators.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Bug Dtype Conversions Unexpected or buggy dtype conversions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bool Ops: One bug hides another
5 participants