Repository navigation
Improving error message for width and position type mismatch in violinplot #30752
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
Changes from 7 commits
7b44fcb
4d9c8cd
555f4d5
c40820b
2cb8aba
8ff4f12
b0862b8
cb23c70
8b3e2fd
07a4119
4db1bf7
3e6bb85
82810c4
fa091cf
f03f086
94bcd9b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4121,6 +4121,81 @@ def test_violinplot_sides(): | |
| showextrema=True, showmedians=True, side=side) | ||
|
|
||
|
|
||
| def violin_plot_stats(): | ||
| datetimes = [ | ||
| datetime.datetime(2023, 2, 10), | ||
| datetime.datetime(2023, 5, 18), | ||
| datetime.datetime(2023, 6, 6) | ||
| ] | ||
| return [{ | ||
| 'coords': datetimes, | ||
| 'vals': [1.2, 2.8, 1.5], | ||
| 'mean': 1.84, | ||
| 'median': 1.5, | ||
| 'min': 1.2, | ||
| 'max': 2.8, | ||
| 'quantiles': [1.2, 1.5, 2.8] | ||
| }, { | ||
| 'coords': datetimes, | ||
| 'vals': [0.8, 1.1, 0.9], | ||
| 'mean': 0.94, | ||
| 'median': 0.9, | ||
| 'min': 0.8, | ||
| 'max': 1.1, | ||
| 'quantiles': [0.8, 0.9, 1.1] | ||
| }] | ||
|
timhoffm marked this conversation as resolved.
|
||
|
|
||
|
|
||
| def test_datetime_positions_with_datetime64(): | ||
| """Test that datetime positions with float widths raise TypeError.""" | ||
| fig, ax = plt.subplots() | ||
| positions = [np.datetime64('2020-01-01'), np.datetime64('2021-01-01')] | ||
| widths = [0.5, 1.0] | ||
| with pytest.raises(TypeError, | ||
| match="np.datetime64 'position' values, require np.timedelta64 'widths'"): | ||
|
timhoffm marked this conversation as resolved.
Outdated
|
||
| ax.violin(violin_plot_stats(), positions=positions, widths=widths) | ||
|
|
||
|
|
||
| def test_datetime_positions_with_float_widths_raises(): | ||
| """Test that datetime positions with float widths raise TypeError.""" | ||
| fig, ax = plt.subplots() | ||
| positions = [datetime.datetime(2020, 1, 1), datetime.datetime(2021, 1, 1)] | ||
| widths = [0.5, 1.0] | ||
| with pytest.raises(TypeError, | ||
| match="datetime/date 'position' values, require timedelta 'widths'"): | ||
|
timhoffm marked this conversation as resolved.
Outdated
|
||
| ax.violin(violin_plot_stats(), positions=positions, widths=widths) | ||
|
|
||
|
|
||
| def test_datetime_positions_with_scalar_float_width_raises(): | ||
| """Test that datetime positions with scalar float width raise TypeError.""" | ||
| fig, ax = plt.subplots() | ||
| positions = [datetime.datetime(2020, 1, 1), datetime.datetime(2021, 1, 1)] | ||
| widths = 0.75 | ||
| with pytest.raises(TypeError, | ||
| match="datetime/date 'position' values, require timedelta 'widths'"): | ||
|
timhoffm marked this conversation as resolved.
Outdated
|
||
| ax.violin(violin_plot_stats(), positions=positions, widths=widths) | ||
|
|
||
|
|
||
| def test_numeric_positions_with_float_widths_ok(): | ||
| """Test that numeric positions with float widths work.""" | ||
| fig, ax = plt.subplots() | ||
| positions = [1.0, 2.0] | ||
| widths = [0.5, 1.0] | ||
| ax.violin(violin_plot_stats(), positions=positions, widths=widths) | ||
|
timhoffm marked this conversation as resolved.
|
||
|
|
||
|
|
||
| def test_mixed_positions_datetime_and_numeric_behaves(): | ||
|
hasanrashid marked this conversation as resolved.
Outdated
|
||
| """Test that mixed datetime and numeric positions | ||
| with float widths raise TypeError. | ||
| """ | ||
| fig, ax = plt.subplots() | ||
| positions = [datetime.datetime(2020, 1, 1), 2.0] | ||
| widths = [0.5, 1.0] | ||
| with pytest.raises(TypeError, | ||
| match="datetime/date 'position' values, require timedelta 'widths'"): | ||
|
||
| ax.violin(violin_plot_stats(), positions=positions, widths=widths) | ||
|
timhoffm marked this conversation as resolved.
|
||
|
|
||
|
|
||
| def test_violinplot_bad_positions(): | ||
| ax = plt.axes() | ||
| # First 9 digits of frac(sqrt(47)) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.