Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add datetime testing for boxplot #26986

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

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions lib/matplotlib/tests/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import numpy as np

import pytest

import pandas as pd
import matplotlib.pyplot as plt
import matplotlib as mpl

Expand Down Expand Up @@ -86,12 +86,19 @@ def test_barh(self):
fig, ax = plt.subplots()
ax.barh(...)

@pytest.mark.xfail(reason="Test for boxplot not written yet")
# @pytest.mark.xfail(reason="Test for boxplot not written yet")
@mpl.style.context("default")
def test_boxplot(self):
fig, ax = plt.subplots()
ax.boxplot(...)

df = pd.DataFrame({'date': pd.to_datetime(['2023-01-01', '2023-02-01', '2023-03-01', '2023-04-01', '2023-05-01']),
Copy link
Member

Choose a reason for hiding this comment

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

Can we do a numpy/list of datetime object version of this?

We do not want to test Pandas converters here, we want to test our own. (We actually do have a few tests to make sure we don't fully break pandas elsewhere, but that is not the intent of this module)

Copy link
Author

Choose a reason for hiding this comment

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

okay !! I'm gonna change this..

'value': [10, 20, 30, 40, 50]})
plt.figure()
plt.bar(df['value'], df['date'])
Copy link
Member

Choose a reason for hiding this comment

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

A bar graph is not a boxplot, and therefore does fit this unit test

Also a (vertical) bar graph with date values on the y axis will generally need a bottom argument as there is nothing about 1970-01-01 that is likely meaningful to the plot you are making.

Copy link
Author

Choose a reason for hiding this comment

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

i'll remove the bar graph..

df.boxplot(by='date')
plt.xlabel('Date')
plt.ylabel('Value')
plt.title('Boxplot with dates on the x-axis')
plt.show()

@pytest.mark.xfail(reason="Test for broken_barh not written yet")
@mpl.style.context("default")
def test_broken_barh(self):
Expand Down Expand Up @@ -395,3 +402,8 @@ def test_vlines(self):
def test_xcorr(self):
fig, ax = plt.subplots()
ax.xcorr(...)

instance = TestDatetimePlotting()


instance.test_boxplot()
Comment on lines +406 to +409
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
instance = TestDatetimePlotting()
instance.test_boxplot()

This seems to have been put in for testing purposes

Copy link
Author

Choose a reason for hiding this comment

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

yes this i forgot to remove