-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: Line plots aligned from start #57594 #57713
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
Conversation
… the ones in the resulting plot * Added test_period_range_content which tests if plotted dates are equal to generated dates using period_range * Added test_date_range_content which tests if plotted dates are equal to generated dates using date_range
* Moved the checking of the plot data to a separate function * Added more frequencies to be tested
2-add-tests
….py to test frequencies with koefficient > 1. Also removed redundant test called test_construction_from_string_monthly since the updated test_construction_from_string covers the same thing.
#2 Refactor: Updated test_construction_from_string::test_period_range…
Thank you for working on this @NoelMT. Do you mind adding plots to this PR (as a comment or in the description) that show how things are rendered before and after your changes please? That would give context to reviewers and it'll make reviewing much easier. Thanks! |
@@ -310,7 +310,7 @@ def maybe_convert_index(ax: Axes, data: NDFrameT) -> NDFrameT: | |||
if isinstance(data.index, ABCDatetimeIndex): | |||
data = data.tz_localize(None).to_period(freq=freq_str) | |||
elif isinstance(data.index, ABCPeriodIndex): | |||
data.index = data.index.asfreq(freq=freq_str) | |||
data.index = data.index.asfreq(freq=freq_str, how = "S") #Lineplot alignes to the start of period |
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.
Could you please check ruff
, ruff-format
and codespell
errors on line 313
?
If you try the following command: pre-commit run --all-file
, it should help fix these errors.
@@ -113,34 +119,6 @@ def test_construction_from_string(self, freq_offset, freq_period): | |||
result = period_range(start=end, end=start, freq=freq_period, name="foo") | |||
tm.assert_index_equal(result, expected) | |||
|
|||
def test_construction_from_string_monthly(self): |
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.
Thank you for noticing code duplication in pandas/tests/indexes/period/test_period_range.py
. I am not sure how it’s related to this bug. Could you please move these changes to separate PR?
@@ -69,6 +70,31 @@ def test_fontsize_set_correctly(self): | |||
for label in ax.get_xticklabels() + ax.get_yticklabels(): | |||
assert label.get_fontsize() == 2 | |||
|
|||
@pytest.mark.parametrize("freq", ["20s","3s","60min","5min","7h","4D","8W","11M","2Q","Y", "3Y", "10Y"]) |
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.
pre-commit run --all-file
fails. Could you please check it?
@@ -69,6 +70,31 @@ def test_fontsize_set_correctly(self): | |||
for label in ax.get_xticklabels() + ax.get_yticklabels(): | |||
assert label.get_fontsize() == 2 | |||
|
|||
@pytest.mark.parametrize("freq", ["20s","3s","60min","5min","7h","4D","8W","11M","2Q","Y", "3Y", "10Y"]) | |||
def test_period_range_content(self, freq): | |||
# Setup your DataFrame as in your scenario |
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.
instead of the comments, e.g. # Setup your DataFrame as in your scenario
, could you please just add the number of GitHub issue: # GH#57594
Thanks @NoelMT for working on this. Seems like it will fix the problem with visualisation of
plot before: ![]() plot after: ![]() |
@NoelMT could you please add a note to pandas/doc/source/whatsnew/v3.0.0.rst Line 356 in dc19148
|
This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this. |
Thanks for the pull request, but it appears to have gone stale. If interested in continuing, please merge in the main branch, address any review comments and/or failing tests, and we can reopen. |
#57594 BUG: df.plot makes a shift to the right if frequency multiplies to n > 1
The cause of this bug is that by default all elements are generated to align to the end of
a period instead of at the start and the period technically does not end at the start of
the last period but rather just before the period subsequent to the last period. To fix this
problem we therefore passed a parameter stating that the elements should be aligned to
the start of the period instead of the end. Parameter "how=S" was added in pandas/plotting/_matplotlib/timeseries.py::maybe_convert_index(),
on the function call data.index.asfreq(freq=freq_str, how = "S").
Additional tests were added to test whether input data match data in plot and one test was merged into one the added test to reduce code duplication.