-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TST, TYP: _use_dynamic_x #34487
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
TST, TYP: _use_dynamic_x #34487
Conversation
ive been looking at this for the last couple days. AFAICT the idea is that not all DateOffset subclasses can be the .freq for a Period, so if we see a DateOffset here, if it does not represent a valid Period, we look to see if there is another offset that does represent a valid Period and is "close enough" by some heuristic. I think the Easter offset might be an example that returns None |
Looks like theres a lot of untested code in these files, some may be pruneable: https://codecov.io/gh/pandas-dev/pandas/tree/master/pandas/plotting/_matplotlib |
Hey @jbrockmendel , thanks for your input
Yes, it is the case that get_period_alias('Easter') is None
Out[4]: True But how would you make a DataFrame where the index has I'm struggling with the intuition behind this function - do you know why is it called AFAICT, if the
|
I don't know if it is relevant for the code you are changing, but an example frequency for which you can make a DataFrame with such an index, and for which there is no period alias:
|
Thanks @jorisvandenbossche ! Yes, that would be relevant - I'll change this PR so there's a test which hits these lines |
@jorisvandenbossche @jbrockmendel thanks for your help here I've added a test which uses But when I try replacing freq = Easter()
bts = tm.makeTimeSeries(5).asfreq(freq)
_, ax = self.plt.subplots()
bts.plot(ax=ax) then when we get here, we have freq
Out[2]: <Easter>
get_period_alias(freq)
Traceback (most recent call last):
File "/home/marco/.conda/envs/pandas-dev/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 3331, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-3-1cfff0cb20d2>", line 1, in <module>
get_period_alias(freq)
File "/home/marco/pandas-dev/pandas/plotting/_matplotlib/timeseries.py", line 167, in get_period_alias
freq = freq.rule_code
File "pandas/_libs/tslibs/offsets.pyx", line 532, in pandas._libs.tslibs.offsets.BaseOffset.rule_code.__get__
File "pandas/_libs/tslibs/offsets.pyx", line 528, in pandas._libs.tslibs.offsets.BaseOffset._prefix.__get__
NotImplementedError: Prefix not defined which was reported in #26921 |
the annotation looks right, havent looked closely at the tests |
Hello @MarcoGorelli! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found: There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2020-06-04 13:19:04 UTC |
lgtm. @jorisvandenbossche ok here? |
Thanks @MarcoGorelli ! |
This condition (which, from the current plotting test suite, is unreachable) was introduced in #9814, when
_use_dynamic_x
was written.Is there any reason why
get_period_alias(freq)
would returnNone
iffreq
is a valid time frequency? If so, I'll add a test - else, this PR removes unreachable code.Added an annotation for
data
and the return type while I was here - is there a way to annotateax
?UPDATE
As it turns out (thanks jbrockmendel and jorisvandenbossche), this line can be hit, so I've included a test which does