Skip to content

REF: Refactor Datetimelike delegation #24039

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

Merged
merged 7 commits into from
Dec 3, 2018

Conversation

TomAugspurger
Copy link
Contributor

This is a generalization of PeriodIndex's dispatching to
PeriodArray, without any actual changes yet. This is split
from #24024, where DatetimeIndex and TimedeltaIndex will
implement and inherit from delgates similiar to PeriodDelegateMixin.

This is a generalization of PeriodIndex's dispatching to
PeriodArray, without any actual changes yet. This is split
from pandas-dev#24024, where DatetimeIndex and TimedeltaIndex will
implement and inherit from delgates similiar to PeriodDelegateMixin.
@pep8speaks
Copy link

Hello @TomAugspurger! Thanks for submitting the PR.

@TomAugspurger TomAugspurger added the Refactor Internal refactoring of code label Dec 1, 2018
@TomAugspurger TomAugspurger added this to the 0.24.0 milestone Dec 1, 2018
@TomAugspurger
Copy link
Contributor Author

These latest two commits have some actual changes:

  1. Removes "delegation" for size, shape, and asi8. These were being overwritten anyway (I think).
  2. Adds delegation for asfreq and to_timestamp. I don't understand my earlier comment about why they couldn't be dispatched normally (but perhaps tests will turn something up).

@TomAugspurger TomAugspurger mentioned this pull request Dec 1, 2018
12 tasks
@codecov
Copy link

codecov bot commented Dec 1, 2018

Codecov Report

Merging #24039 into master will increase coverage by 49.88%.
The diff coverage is 96.15%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master   #24039       +/-   ##
===========================================
+ Coverage   42.46%   92.35%   +49.88%     
===========================================
  Files         161      161               
  Lines       51557    51562        +5     
===========================================
+ Hits        21892    47618    +25726     
+ Misses      29665     3944    -25721
Flag Coverage Δ
#multiple 90.75% <96.15%> (?)
#single 42.47% <65.38%> (+0.01%) ⬆️
Impacted Files Coverage Δ
pandas/core/indexes/period.py 93.06% <100%> (+53.23%) ⬆️
pandas/core/indexes/datetimelike.py 97.59% <95%> (+45.05%) ⬆️
pandas/core/computation/pytables.py 92.37% <0%> (+0.3%) ⬆️
pandas/io/pytables.py 92.3% <0%> (+0.92%) ⬆️
pandas/util/_test_decorators.py 93.24% <0%> (+4.05%) ⬆️
pandas/compat/__init__.py 58.36% <0%> (+8.17%) ⬆️
pandas/core/config_init.py 99.24% <0%> (+9.84%) ⬆️
pandas/core/reshape/util.py 100% <0%> (+11.53%) ⬆️
pandas/compat/numpy/__init__.py 92.85% <0%> (+14.28%) ⬆️
pandas/core/computation/common.py 85.71% <0%> (+14.28%) ⬆️
... and 121 more

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 5b0610b...de13b2d. Read the comment docs.

@codecov
Copy link

codecov bot commented Dec 1, 2018

Codecov Report

Merging #24039 into master will decrease coverage by 49.85%.
The diff coverage is 67.85%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master   #24039       +/-   ##
===========================================
- Coverage   92.31%   42.46%   -49.86%     
===========================================
  Files         161      161               
  Lines       51562    51568        +6     
===========================================
- Hits        47599    21896    -25703     
- Misses       3963    29672    +25709
Flag Coverage Δ
#multiple ?
#single 42.46% <67.85%> (+0.01%) ⬆️
Impacted Files Coverage Δ
pandas/core/indexes/period.py 40.84% <100%> (-52.23%) ⬇️
pandas/core/indexes/datetimelike.py 53.63% <55%> (-43.79%) ⬇️
pandas/io/formats/latex.py 0% <0%> (-100%) ⬇️
pandas/core/categorical.py 0% <0%> (-100%) ⬇️
pandas/io/sas/sas_constants.py 0% <0%> (-100%) ⬇️
pandas/tseries/plotting.py 0% <0%> (-100%) ⬇️
pandas/tseries/converter.py 0% <0%> (-100%) ⬇️
pandas/io/formats/html.py 0% <0%> (-97.98%) ⬇️
pandas/core/groupby/categorical.py 0% <0%> (-95.46%) ⬇️
pandas/io/sas/sas7bdat.py 0% <0%> (-91.17%) ⬇️
... and 121 more

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 367efb2...1f3f4c9. Read the comment docs.

def _delegate_method(self, name, *args, **kwargs):
result = operator.methodcaller(name, *args, **kwargs)(self._data)
if name not in self._raw_methods:
result = Index(result, name=self.name)
Copy link
Member

Choose a reason for hiding this comment

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

this will need checks for 2-tuples in divmod and rdivmod, for scalars for eventual reduction ops

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think all the delegated methods return a single value.

Copy link
Member

Choose a reason for hiding this comment

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

If #23885 goes through that will change

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gotcha. I'd prefer to wait until we can hit that code path before worrying about it.

Copy link
Member

Choose a reason for hiding this comment

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

Totally fair.

@@ -855,3 +857,48 @@ def f(self):
f.__name__ = fget.__name__
f.__doc__ = fget.__doc__
return property(f)


class DatetimelikeDelegateMixin(PandasDelegate):
Copy link
Member

Choose a reason for hiding this comment

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

Is PandasDelegate overkill for this situation? It's not like Series.dt where we construct an object and need to cache it. Couldn't we just use something like:

def pass_through_methods(names):
    def decorator(cls):
        for name in names:
            method = wrap_array_method(...)
            setattr(cls, name, method)
        return cls

There's definitely overlap with the PandasDelegate machinery, but I think that machinery makes for really dense reading, so should be reserved for when we really need it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps you're thinking of Properties (which subclasses PandasDelegate)? PandasDelegate doesn't have an __init__, it just handles registering and creating the delegated properties.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But, I don't have a strong preference of one of the other. We use PandasDelegate on master, for period, so this PR is a strict generalization of that.

@jreback
Copy link
Contributor

jreback commented Dec 2, 2018

lgtm. merge when ready @TomAugspurger @jbrockmendel

@jbrockmendel
Copy link
Member

LGTM. I might poke at simplifying down the road, but that shouldn't be a blocker.

@jreback
Copy link
Contributor

jreback commented Dec 2, 2018

ok I merged the other one, so @TomAugspurger if you can rebase

@jreback
Copy link
Contributor

jreback commented Dec 3, 2018

lgtm. ping on green.

@jreback jreback merged commit f06b969 into pandas-dev:master Dec 3, 2018
@jreback
Copy link
Contributor

jreback commented Dec 3, 2018

thanks @TomAugspurger

Pingviinituutti pushed a commit to Pingviinituutti/pandas that referenced this pull request Feb 28, 2019
Pingviinituutti pushed a commit to Pingviinituutti/pandas that referenced this pull request Feb 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Refactor Internal refactoring of code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants