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

De-duplicate masking/fallback logic in ops #19613

Merged
merged 5 commits into from
Feb 13, 2018

Conversation

jbrockmendel
Copy link
Member

Some nice deletions here.

xrav = xrav[mask]
if xrav.size:
with np.errstate(all='ignore'):
result[mask] = op(xrav, y)
Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think this case is reached/reachable. If y is an ndarray then most non-trivial cases should have shape mismatches if this were ever reached.

@codecov
Copy link

codecov bot commented Feb 9, 2018

Codecov Report

Merging #19613 into master will decrease coverage by 0.01%.
The diff coverage is 96%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #19613      +/-   ##
==========================================
- Coverage   91.62%    91.6%   -0.02%     
==========================================
  Files         150      150              
  Lines       48790    48795       +5     
==========================================
- Hits        44703    44701       -2     
- Misses       4087     4094       +7
Flag Coverage Δ
#multiple 89.98% <96%> (-0.02%) ⬇️
#single 41.74% <8%> (+0.01%) ⬆️
Impacted Files Coverage Δ
pandas/core/frame.py 97.16% <ø> (-0.27%) ⬇️
pandas/core/series.py 94.56% <100%> (-0.05%) ⬇️
pandas/core/ops.py 96.83% <95.83%> (+1.61%) ⬆️
pandas/plotting/_converter.py 65.22% <0%> (-1.74%) ⬇️
pandas/core/dtypes/dtypes.py 96.08% <0%> (ø) ⬆️
pandas/io/formats/format.py 96.25% <0%> (+0.01%) ⬆️
pandas/core/groupby.py 92.2% <0%> (+0.07%) ⬆️
pandas/core/arrays/base.py 60.6% <0%> (+3.93%) ⬆️

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 b835127...221f8a6. Read the comment docs.

if isinstance(y, allowed_types):
yrav = y.ravel()
mask = notna(xrav) & notna(yrav)
result[mask] = op(np.array(list(xrav[mask])),
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you know why we build the intermediate list here?

Copy link
Member Author

Choose a reason for hiding this comment

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

No idea. I can try removing it and see if that affects any tests.

Copy link
Member Author

Choose a reason for hiding this comment

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

Looks like a complex-dtype test would be affected.

@jbrockmendel jbrockmendel changed the title De-duplicating masking/fallback logic in ops De-duplicate masking/fallback logic in ops Feb 10, 2018
@jreback jreback added Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Numeric Operations Arithmetic, Comparison, and Logical operations Clean labels Feb 10, 2018
@jreback jreback added this to the 0.23.0 milestone Feb 10, 2018
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

lgtm. some doc-strings

# Masking NA values and fallbacks for operations numpy does not support

def fill_binop(left, right, fill_value):
if fill_value is not None:
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 add a doc-string



def mask_cmp_op(x, y, op, allowed_types):
# TODO: Can we make the allowed_types arg unnecessary?
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 add a doc-string

@@ -3920,17 +3920,7 @@ def _combine_frame(self, other, func, fill_value=None, level=None):
new_index, new_columns = this.index, this.columns

def _arith_op(left, right):
Copy link
Contributor

Choose a reason for hiding this comment

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

you might be able to simplify this even more here (IOW remove _arith_op) and just in-line it

Copy link
Member Author

Choose a reason for hiding this comment

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

This overlaps with #19611. This will probably get in before that does, so I'll take a look at this suggestion after rebasing there.

Copy link
Contributor

Choose a reason for hiding this comment

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

aok

@jreback jreback merged commit d9551c8 into pandas-dev:master Feb 13, 2018
@jreback
Copy link
Contributor

jreback commented Feb 13, 2018

thanks!

harisbal pushed a commit to harisbal/pandas that referenced this pull request Feb 28, 2018
@jbrockmendel jbrockmendel deleted the ops_masking2 branch June 22, 2018 03:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Clean Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Numeric Operations Arithmetic, Comparison, and Logical operations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants