-
-
Notifications
You must be signed in to change notification settings - Fork 19.4k
DOC: better document Dtypes docstrings + avoid sphinx warnings #26067
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
DOC: better document Dtypes docstrings + avoid sphinx warnings #26067
Conversation
Codecov Report
@@ Coverage Diff @@
## master #26067 +/- ##
===========================================
- Coverage 91.95% 40.75% -51.21%
===========================================
Files 175 175
Lines 52427 52514 +87
===========================================
- Hits 48208 21400 -26808
- Misses 4219 31114 +26895
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #26067 +/- ##
==========================================
- Coverage 91.99% 91.98% -0.01%
==========================================
Files 175 175
Lines 52383 52394 +11
==========================================
+ Hits 48188 48196 +8
- Misses 4195 4198 +3
Continue to review full report at Codecov.
|
|
@jreback could you take a look at this, if you have some time? (specifically the actual code changes in the dtypes, as this might have some implications for pickling) |
jreback
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks fine, just being sure we actually have enough coverage for pickling of these
| def __setstate__(self, state): | ||
| # for pickle compat. | ||
| self._freq = state['freq'] | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we have a round-trip on this test? shouldn't you also need __getstate__? or maybe not as you are setting _freq which is now good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
__getstate__ is implemented in the super class:
pandas/pandas/core/dtypes/dtypes.py
Lines 152 to 154 in 455a2cd
| def __getstate__(self): | |
| # pickle support; we don't want to pickle the cache | |
| return {k: getattr(self, k, None) for k in self._metadata} |
Added in 154a647
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And it's the round trip test that was failing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, what if you move _freq into metdata then? (and so on for the other subclasses)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I have been thinking about that as well. _metadata is also used for other things though (that are included in the EA interface, this __getstate__ is only for our internal dtypes). Eg for equality. For equality it would not matter if freq or _freq is included, but if we would want to use it eg also for a default repr, then it need to be the public attributes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, yeah they are coupled. i don't really like having to be explicit about the pickle compat here.....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't really like having to be explicit about the pickle compat here.....
Yep, I agree. Although it is consistent with how it is already done in the other dtypes (Categorical actually has the same), it would be nice to clean it up. I could also add a different _metadata_pickles list, so we can handle both getstate and setstate in the PandasExtensionDtype superclass. Of course that doesn't change the implementation, but it does reduce some duplication in the code.
It's also doing the same as what is already done in DatetimeTZDtype: pandas/pandas/core/dtypes/dtypes.py Lines 720 to 723 in 455a2cd
I was only wondering if we need to worry about old pickle compat, as the above code I am showing was done in the initial implementation of DatetimeTZDtype, while for PeriodDtype that I am changing here, we already have released versions without this. |
|
right, see my comment above, I think that this might just work if you move the private attributes into _metadata (and leave the accessors as propertys) |
|
@jreback are you fine with merging this as is? |
jreback
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see my comment otherwise lgtm
pandas/core/dtypes/dtypes.py
Outdated
| return is_dtype_equal(self.subtype, other.subtype) | ||
|
|
||
| def __setstate__(self, state): | ||
| # for pickle compat. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think would add a bit more comment here. (in all of the setstates to indicate why this is needed, maybe reference this issue)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, expanded the comment!
|
something faiking merge on green |
|
thanks @jorisvandenbossche |
class_without_autosummarytemplate for the dtypes (similar to whatCategoricalDtypealready did) to avoid a bunch of sphinx warnings