@@ -105,7 +105,7 @@ def test_plot_enforces_range_clipping(sample_dataframe):
105
105
106
106
107
107
@pytest .mark .usefixtures ("_mock_color_generators" , "_mock_gu_functions" )
108
- def test_plot_with_range_fillna (sample_dataframe , mocker ):
108
+ def test_plot_with_range_fillna (sample_dataframe ):
109
109
"""Test the plot function with range fillna."""
110
110
_ , ax = plt .subplots ()
111
111
range_lower = 3
@@ -130,6 +130,79 @@ def test_plot_with_range_fillna(sample_dataframe, mocker):
130
130
assert all (range_lower <= val + np .finfo (np .float64 ).eps <= range_upper for val in clipped_values )
131
131
132
132
133
+ @pytest .mark .usefixtures ("_mock_color_generators" , "_mock_gu_functions" )
134
+ def test_plot_with_range_lower_none (sample_dataframe ):
135
+ """Test the plot function with range_lower=None (no lower bound) and a specific upper bound."""
136
+ _ , ax = plt .subplots ()
137
+ range_upper = 8 # No lower bound
138
+
139
+ result_ax = histogram .plot (
140
+ df = sample_dataframe ,
141
+ value_col = "value_1" ,
142
+ ax = ax ,
143
+ title = "Test Histogram with Upper Bound Only" ,
144
+ range_lower = None ,
145
+ range_upper = range_upper ,
146
+ range_method = "clip" ,
147
+ )
148
+
149
+ # Get the data limits from the resulting Axes object
150
+ x_data = result_ax .patches
151
+ clipped_values = [patch .get_x () for patch in x_data ]
152
+
153
+ # Ensure that the x values (bars' positions) respect the upper bound, but no lower bound is applied
154
+ assert all (val + np .finfo (np .float64 ).eps <= range_upper for val in clipped_values )
155
+
156
+
157
+ @pytest .mark .usefixtures ("_mock_color_generators" , "_mock_gu_functions" )
158
+ def test_plot_with_range_upper_none (sample_dataframe ):
159
+ """Test the plot function with range_upper=None (no upper bound) and a specific lower bound."""
160
+ _ , ax = plt .subplots ()
161
+ range_lower = 3 # No upper bound
162
+
163
+ result_ax = histogram .plot (
164
+ df = sample_dataframe ,
165
+ value_col = "value_1" ,
166
+ ax = ax ,
167
+ title = "Test Histogram with Lower Bound Only" ,
168
+ range_lower = range_lower ,
169
+ range_upper = None ,
170
+ range_method = "clip" ,
171
+ )
172
+
173
+ # Get the data limits from the resulting Axes object
174
+ x_data = result_ax .patches
175
+ clipped_values = [patch .get_x () for patch in x_data ]
176
+
177
+ # Ensure that the x values (bars' positions) respect the lower bound, but no upper bound is applied
178
+ assert all (range_lower <= val + np .finfo (np .float64 ).eps for val in clipped_values )
179
+
180
+
181
+ @pytest .mark .usefixtures ("_mock_color_generators" , "_mock_gu_functions" )
182
+ def test_plot_fillna_outside_range (sample_dataframe ):
183
+ """Test the fillna method, ensuring values outside the range are replaced by NaN."""
184
+ _ , ax = plt .subplots ()
185
+ range_lower = 3
186
+ range_upper = 8
187
+
188
+ result_ax = histogram .plot (
189
+ df = sample_dataframe ,
190
+ value_col = "value_1" ,
191
+ ax = ax ,
192
+ title = "Test Histogram with Range Fillna" ,
193
+ range_lower = range_lower ,
194
+ range_upper = range_upper ,
195
+ range_method = "fillna" ,
196
+ )
197
+
198
+ # Extract data from the resulting Axes
199
+ x_data = result_ax .patches
200
+ clipped_values = [patch .get_x () for patch in x_data ]
201
+
202
+ # Ensure that values outside the range are not plotted (NaN)
203
+ assert all (range_lower <= val + np .finfo (np .float64 ).eps <= range_upper for val in clipped_values )
204
+
205
+
133
206
@pytest .mark .usefixtures ("_mock_color_generators" , "_mock_gu_functions" )
134
207
def test_plot_single_histogram_series (sample_series ):
135
208
"""Test the plot function with a pandas series."""
0 commit comments