Skip to content

Docstrings, de-duplicate EAMixin/DatetimeLikeIndex __new__ code #21926

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 6 commits into from
Jul 20, 2018

Conversation

jbrockmendel
Copy link
Member

There's a lot of duplication in the constructors and constructor-helpers. This starts to whittle that down, writes some docstrings long the way.

Also use ExtensionOpsMixin to define comparison operators on the EAMixin classes.

We determined that the DatetimeIndex._local_timestamps method had an unecessary monotonicy check, so took that out.

@codecov
Copy link

codecov bot commented Jul 16, 2018

Codecov Report

Merging #21926 into master will increase coverage by <.01%.
The diff coverage is 95.65%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #21926      +/-   ##
==========================================
+ Coverage   91.96%   91.97%   +<.01%     
==========================================
  Files         166      166              
  Lines       50329    50297      -32     
==========================================
- Hits        46287    46261      -26     
+ Misses       4042     4036       -6
Flag Coverage Δ
#multiple 90.37% <95.65%> (ø) ⬆️
#single 42.24% <72.82%> (ø) ⬆️
Impacted Files Coverage Δ
pandas/core/arrays/base.py 87.85% <ø> (ø) ⬆️
pandas/core/indexes/timedeltas.py 91.39% <100%> (-0.14%) ⬇️
pandas/core/arrays/period.py 91.18% <100%> (-0.17%) ⬇️
pandas/tseries/frequencies.py 95.9% <100%> (ø) ⬆️
pandas/core/arrays/datetimes.py 96.3% <100%> (+0.17%) ⬆️
pandas/core/indexes/datetimelike.py 97.34% <100%> (-0.02%) ⬇️
pandas/core/indexes/datetimes.py 95.12% <100%> (-0.05%) ⬇️
pandas/core/indexes/period.py 93.2% <100%> (ø) ⬆️
pandas/core/arrays/timedeltas.py 91.75% <72.72%> (+1.91%) ⬆️
pandas/core/arrays/datetimelike.py 94.48% <97.43%> (+0.41%) ⬆️

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 537b65c...6eb2f8b. Read the comment docs.

@gfyoung gfyoung added Clean ExtensionArray Extending pandas with custom dtypes or arrays. labels Jul 16, 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.

looks fine. if you can just update the docs in arrays/base.py when you add api there

@@ -634,6 +634,11 @@ class ExtensionOpsMixin(object):
"""
A base class for linking the operators to their dunder names
"""

@classmethod
Copy link
Contributor

Choose a reason for hiding this comment

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

ideally should add doc-strings & to the top-level docs, as this is API

Copy link
Member Author

Choose a reason for hiding this comment

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

OK. I think I'll revert this part of the PR as out-of-scope and do the docs bit separately.

try:
dtype = DatetimeTZDtype.construct_from_string(dtype)
dtz = getattr(dtype, 'tz', None)
if dtz 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 do this ?

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 update this

Copy link
Member Author

Choose a reason for hiding this comment

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

Already done

Copy link
Contributor

Choose a reason for hiding this comment

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

hmm, does tz_compare not take None as an arg? hmm make should add the check there? as I don't think we check for None's elsewhere (not really sure about this)

Copy link
Member Author

Choose a reason for hiding this comment

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

None-tz comparisons are a pretty special case that get handled separately. I’m OK with tzcompare not taking None.

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.

minor comments


import pandas.core.common as com
from pandas.core.algorithms import checked_add_with_arr

from .base import ExtensionOpsMixin
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 do absolute imports

Copy link
Member Author

Choose a reason for hiding this comment

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

Tried it, causes import-time errors

Copy link
Contributor

Choose a reason for hiding this comment

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

i see, we import in init all of the extension arrays which import this. hmm.

@@ -464,7 +468,10 @@ def _addsub_offset_array(self, other, op):
"{cls} not vectorized"
.format(cls=type(self).__name__), PerformanceWarning)

res_values = op(self.astype('O').values, np.array(other))
Copy link
Contributor

Choose a reason for hiding this comment

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

is it worth a branch here in is_extension_dtype?

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 think values_from_object is a pretty clean solution to this.

@jreback jreback added this to the 0.24.0 milestone Jul 18, 2018
@jbrockmendel
Copy link
Member Author

Thoughts? The next step here is to deal with cached_range issues.


import pandas.core.common as com
from pandas.core.algorithms import checked_add_with_arr

from .base import ExtensionOpsMixin
Copy link
Contributor

Choose a reason for hiding this comment

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

i see, we import in init all of the extension arrays which import this. hmm.

try:
dtype = DatetimeTZDtype.construct_from_string(dtype)
dtz = getattr(dtype, 'tz', None)
if dtz 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 update this

try:
dtype = DatetimeTZDtype.construct_from_string(dtype)
dtz = getattr(dtype, 'tz', None)
if dtz 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.

hmm, does tz_compare not take None as an arg? hmm make should add the check there? as I don't think we check for None's elsewhere (not really sure about this)

@jbrockmendel
Copy link
Member Author

@jreback since we're on a roll I'd like to push this through, get started on the next steps over the weekend. Thoughts?

@jreback jreback merged commit 8c50682 into pandas-dev:master Jul 20, 2018
@jreback
Copy link
Contributor

jreback commented Jul 20, 2018

sure. my comments were minor.

@jbrockmendel jbrockmendel deleted the mvmore branch July 20, 2018 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Clean ExtensionArray Extending pandas with custom dtypes or arrays.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants