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

REF/CLN: ops boilerplate #23853 #24846

Closed
wants to merge 16 commits into from
Closed

Conversation

makbigc
Copy link
Contributor

@makbigc makbigc commented Jan 20, 2019

Implement a wrapper class other than a single decorator. It is tidier to add more conditions for ops later.

@codecov
Copy link

codecov bot commented Jan 20, 2019

Codecov Report

Merging #24846 into master will decrease coverage by <.01%.
The diff coverage is 89.13%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #24846      +/-   ##
==========================================
- Coverage   92.39%   92.38%   -0.01%     
==========================================
  Files         166      166              
  Lines       52378    52400      +22     
==========================================
+ Hits        48393    48412      +19     
- Misses       3985     3988       +3
Flag Coverage Δ
#multiple 90.81% <89.13%> (-0.01%) ⬇️
#single 42.94% <84.78%> (+0.03%) ⬆️
Impacted Files Coverage Δ
pandas/core/arrays/__init__.py 100% <ø> (ø) ⬆️
pandas/core/arrays/integer.py 96.61% <100%> (+0.28%) ⬆️
pandas/core/arrays/timedeltas.py 88.33% <100%> (+0.12%) ⬆️
pandas/core/arrays/period.py 98.51% <100%> (-0.02%) ⬇️
pandas/core/arrays/datetimes.py 97.76% <100%> (-0.02%) ⬇️
pandas/core/arrays/base.py 96.17% <86.84%> (-2.09%) ⬇️

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 f4458c1...6d0f4dd. Read the comment docs.

@codecov
Copy link

codecov bot commented Jan 20, 2019

Codecov Report

Merging #24846 into master will decrease coverage by <.01%.
The diff coverage is 90.9%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #24846      +/-   ##
==========================================
- Coverage   92.38%   92.38%   -0.01%     
==========================================
  Files         166      166              
  Lines       52398    52417      +19     
==========================================
+ Hits        48406    48423      +17     
- Misses       3992     3994       +2
Flag Coverage Δ
#multiple 90.8% <90.9%> (-0.01%) ⬇️
#single 42.92% <87.27%> (+0.03%) ⬆️
Impacted Files Coverage Δ
pandas/core/arrays/datetimelike.py 97.83% <100%> (+0.15%) ⬆️
pandas/core/arrays/period.py 98.51% <100%> (-0.02%) ⬇️
pandas/core/arrays/timedeltas.py 88.43% <100%> (+0.12%) ⬆️
pandas/core/arrays/categorical.py 95.96% <100%> (-0.02%) ⬇️
pandas/core/arrays/datetimes.py 97.77% <100%> (-0.03%) ⬇️
pandas/core/ops.py 93.93% <86.84%> (-0.36%) ⬇️
pandas/util/testing.py 88.13% <0%> (+0.09%) ⬆️

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 2b16e2e...57463cc. Read the comment docs.

@@ -1118,3 +1119,58 @@ def _create_arithmetic_method(cls, op):
@classmethod
def _create_comparison_method(cls, op):
return cls._create_method(op, coerce_to_dtype=False)


class CompWrapper(object):
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 go in core.ops

@wraps(comp)
def wrapper(comp_self, comp_other):
if isinstance(comp_other, (ABCDataFrame,
ABCSeries, ABCIndexClass)):
Copy link
Member

Choose a reason for hiding this comment

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

this is only accurate if comp_self is an EA. Also consider Index and Series

@jbrockmendel
Copy link
Member

To close #23853 this would need to handle arithmetic ops in addition to comparison ops

@@ -496,22 +496,17 @@ def _values_for_argsort(self):

@classmethod
def _create_comparison_method(cls, op):
@CompWrapper(validate_len=True, inst_from_senior_cls=True)
Copy link
Member

Choose a reason for hiding this comment

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

this changes the behavior to defer to DataFrame as well as Series and Index. I agree that it should do this eventually, but IIRC there are tests that fail if we start doing it now.

@jbrockmendel
Copy link
Member

Any reason not to wrap Categorical comparison ops?

@gfyoung gfyoung added Refactor Internal refactoring of code Internals Related to non-user accessible pandas implementation Clean labels Jan 20, 2019
@@ -136,6 +137,62 @@ def maybe_upcast_for_op(obj):
return obj


class CompWrapper(object):
Copy link
Member

Choose a reason for hiding this comment

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

Haven't looked at implementation in detail but can you add a docstring for this class to describe utility and parameters? Also what is the reasoning for going this route instead of say a meta class?

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.

not averse to this, but need some very clear documentation in the class definition.

@@ -1143,7 +1140,7 @@ def _time_shift(self, periods, freq=None):

Note this is different from ExtensionArray.shift, which
shifts the *position* of each element, padding the end with
missing values.
missing values.x
Copy link
Contributor

Choose a reason for hiding this comment

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

extra value here

'zerodim', 'inst_from_senior_cls']

def __init__(self,
list_to_array=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 make these arg names even more explict, e.g.
zerodim -> unwrap_zero_dim_arrays
validate_len -> validate_len_of_input_arrays
inst_from_senior_cls -> not really sure what this does, can you make more explicit
list_to_array -> same

return comp(comp_self, comp_other)
return wrapper

def _inst_from_senior_cls(self, comp):
Copy link
Contributor

Choose a reason for hiding this comment

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

add a doc-string to each of these

@jreback
Copy link
Contributor

jreback commented Mar 3, 2019

@jbrockmendel if you'd have a look.

@jbrockmendel
Copy link
Member

@jreback I'm -1 on this as implemented. The point of #23853 is to make all the methods behave the same; this does not do that. And while it technically removes boilerplate, it does so with a net increase in LOC.

Even if merged, this does not close #23853, since there are many methods this isn't applied to.

A better approach would be to write a single decorator with the desired behavior (like #24282) and apply it in subset of methods where it wouldn't change behavior, then gradually expand that subset by fixing the methods with idiosyncratic behavior.

@jreback
Copy link
Contributor

jreback commented Mar 26, 2019

@makbigc if you want to respond to @jbrockmendel comments, alternatively can close.

@jreback
Copy link
Contributor

jreback commented Apr 5, 2019

closing, @makbigc a followup according to @jbrockmendel comments would be ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Clean Internals Related to non-user accessible pandas implementation Refactor Internal refactoring of code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

REF/CLN: ops boilerplate
5 participants