From a0cd3590a5f7e505d9209fb2ebaca470860a4b8b Mon Sep 17 00:00:00 2001 From: noatamir <6564007+noatamir@users.noreply.github.com> Date: Tue, 14 Jun 2022 14:25:05 +0200 Subject: [PATCH 1/4] adding a test for bar plot with intervalrange xaxis --- pandas/tests/plotting/test_misc.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pandas/tests/plotting/test_misc.py b/pandas/tests/plotting/test_misc.py index 9c7996adfed38..d7e10806a2798 100644 --- a/pandas/tests/plotting/test_misc.py +++ b/pandas/tests/plotting/test_misc.py @@ -10,6 +10,7 @@ Index, Series, Timestamp, + interval_range, ) import pandas._testing as tm from pandas.tests.plotting.common import ( @@ -582,3 +583,16 @@ def test_plot_bar_axis_units_timestamp_conversion(self): _check_plot_works(df.plot) s = Series({"A": 1.0}) _check_plot_works(s.plot.bar) + + def test_bar_plt_xaxis_intervalrange(self): + # GH 38969 + # Ensure IntervalIndex x-axis produces a bar plot as expected + from matplotlib.text import Text + + expected = [Text(0, 0, "([0, 1],)"), Text(1, 0, "([1, 2],)")] + s = Series( + [1, 2], + index=[interval_range(0, 2)], + ) + _check_plot_works(s.plot.bar) + assert s.plot.bar().get_xticklabels() == expected From b0ab467514361927fb8138547b8fb5b6ef523cd1 Mon Sep 17 00:00:00 2001 From: Noa Tamir <6564007+noatamir@users.noreply.github.com> Date: Tue, 14 Jun 2022 19:43:06 +0200 Subject: [PATCH 2/4] fixed assert in test --- pandas/tests/plotting/test_misc.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pandas/tests/plotting/test_misc.py b/pandas/tests/plotting/test_misc.py index ad8126a562b08..4d042579701eb 100644 --- a/pandas/tests/plotting/test_misc.py +++ b/pandas/tests/plotting/test_misc.py @@ -610,4 +610,7 @@ def test_bar_plt_xaxis_intervalrange(self): index=[interval_range(0, 2)], ) _check_plot_works(s.plot.bar) - assert s.plot.bar().get_xticklabels() == expected + assert all( + (a.get_text() == b.get_text()) + for a, b in zip(s.plot.bar().get_xticklabels(), expected) + ) From db9401b4d901a057d0f107f6d0a3f3c949dd17b6 Mon Sep 17 00:00:00 2001 From: noatamir <6564007+noatamir@users.noreply.github.com> Date: Tue, 14 Jun 2022 20:06:40 +0200 Subject: [PATCH 3/4] moved import to top --- pandas/tests/plotting/test_misc.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pandas/tests/plotting/test_misc.py b/pandas/tests/plotting/test_misc.py index 4d042579701eb..0c4bae8947db1 100644 --- a/pandas/tests/plotting/test_misc.py +++ b/pandas/tests/plotting/test_misc.py @@ -1,5 +1,6 @@ """ Test cases for misc plot functions """ +from matplotlib.text import Text import numpy as np import pytest @@ -446,7 +447,6 @@ def test_dictionary_color(self): def test_bar_plot(self): # GH38947 # Test bar plot with string and int index - from matplotlib.text import Text expected = [Text(0, 0, "0"), Text(1, 0, "Total")] @@ -465,7 +465,6 @@ def test_bar_plot(self): def test_barh_plot_labels_mixed_integer_string(self): # GH39126 # Test barh plot with string and integer at the same column - from matplotlib.text import Text df = DataFrame([{"word": 1, "value": 0}, {"word": "knowledg", "value": 2}]) plot_barh = df.plot.barh(x="word", legend=None) @@ -602,7 +601,6 @@ def test_plot_bar_axis_units_timestamp_conversion(self): def test_bar_plt_xaxis_intervalrange(self): # GH 38969 # Ensure IntervalIndex x-axis produces a bar plot as expected - from matplotlib.text import Text expected = [Text(0, 0, "([0, 1],)"), Text(1, 0, "([1, 2],)")] s = Series( From 4e9a129feaac6a1d8ceda5d004fc44f6302f4952 Mon Sep 17 00:00:00 2001 From: noatamir <6564007+noatamir@users.noreply.github.com> Date: Tue, 14 Jun 2022 23:08:50 +0200 Subject: [PATCH 4/4] Revert "moved import to top" This reverts commit db9401b4d901a057d0f107f6d0a3f3c949dd17b6. --- pandas/tests/plotting/test_misc.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/tests/plotting/test_misc.py b/pandas/tests/plotting/test_misc.py index 0c4bae8947db1..4d042579701eb 100644 --- a/pandas/tests/plotting/test_misc.py +++ b/pandas/tests/plotting/test_misc.py @@ -1,6 +1,5 @@ """ Test cases for misc plot functions """ -from matplotlib.text import Text import numpy as np import pytest @@ -447,6 +446,7 @@ def test_dictionary_color(self): def test_bar_plot(self): # GH38947 # Test bar plot with string and int index + from matplotlib.text import Text expected = [Text(0, 0, "0"), Text(1, 0, "Total")] @@ -465,6 +465,7 @@ def test_bar_plot(self): def test_barh_plot_labels_mixed_integer_string(self): # GH39126 # Test barh plot with string and integer at the same column + from matplotlib.text import Text df = DataFrame([{"word": 1, "value": 0}, {"word": "knowledg", "value": 2}]) plot_barh = df.plot.barh(x="word", legend=None) @@ -601,6 +602,7 @@ def test_plot_bar_axis_units_timestamp_conversion(self): def test_bar_plt_xaxis_intervalrange(self): # GH 38969 # Ensure IntervalIndex x-axis produces a bar plot as expected + from matplotlib.text import Text expected = [Text(0, 0, "([0, 1],)"), Text(1, 0, "([1, 2],)")] s = Series(