|
1 |
| -import pytest |
2 |
| -import pandas as pd |
3 | 1 | from datetime import datetime as dt
|
| 2 | + |
4 | 3 | import numpy as np
|
| 4 | +import pytest |
5 | 5 |
|
6 |
| -"""targeting #GH40781""" |
| 6 | +from pandas import DataFrame |
7 | 7 |
|
8 |
| -# arbitrary df to test |
9 |
| -df = pd.DataFrame( |
10 |
| - { |
11 |
| - "A" : [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], |
12 |
| - "B": [dt.now() for i in range(0, 10)] |
13 |
| - } |
14 |
| -) |
15 | 8 |
|
16 |
| - |
17 |
| -def test_axis_lim_invalid(): |
18 |
| - global df |
19 |
| - """ |
20 |
| - supplying ranges with str, datetime and |
21 |
| - mixed int,str and float,str dtype to raise |
22 |
| - ValueError. Valid dtypes are np.datetime64 |
23 |
| - int, and float. |
24 |
| - """ |
25 |
| - lim = [ |
26 |
| - ["1", "3"], |
27 |
| - [dt.now(), dt.now()], |
28 |
| - [1, "2"], |
29 |
| - [0.1, "0.2"], |
30 |
| - [np.datetime64(dt.now()), dt.now()] |
31 |
| - ] |
| 9 | +@pytest.mark.parametrize("df, lim", [ |
| 10 | + ( |
| 11 | + DataFrame( |
| 12 | + { |
| 13 | + "A" : [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], |
| 14 | + "B": [dt.now() for i in range(0, 10)] |
| 15 | + } |
| 16 | + ), |
| 17 | + [ |
| 18 | + ["1", "3"], |
| 19 | + [dt.now(), dt.now()], |
| 20 | + [1, "2"], |
| 21 | + [0.1, "0.2"], |
| 22 | + [np.datetime64(dt.now()), dt.now()] |
| 23 | + ] |
| 24 | + ) |
| 25 | +] |
| 26 | +) |
| 27 | +def test_axis_lim_invalid(df, lim): |
32 | 28 | for elem in lim:
|
33 | 29 | with pytest.raises(ValueError, match="`xlim` contains values"):
|
34 | 30 | df.plot.line(x="A", xlim=elem)
|
35 | 31 |
|
36 | 32 |
|
37 |
| -def test_axis_lim_valid(): |
38 |
| - global df |
39 |
| - """ |
40 |
| - supplying ranges with |
41 |
| - valid dtypes: np.datetime64 |
42 |
| - int, and float, this test |
43 |
| - should not raise errors. |
44 |
| - """ |
45 |
| - lim = [ |
46 |
| - [1, 3], |
47 |
| - [np.datetime64(dt.now()), np.datetime64(dt.now())], |
48 |
| - [0.1, 0.2], |
49 |
| - ] |
| 33 | +@pytest.mark.parametrize("df, lim", [ |
| 34 | + ( |
| 35 | + DataFrame( |
| 36 | + { |
| 37 | + "A" : [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], |
| 38 | + "B": [dt.now() for i in range(0, 10)] |
| 39 | + } |
| 40 | + ), |
| 41 | + [ |
| 42 | + [1, 3], |
| 43 | + [0.1, 0.2], |
| 44 | + [np.datetime64(dt.now()), np.datetime64(dt.now())] |
| 45 | + ] |
| 46 | + ) |
| 47 | +] |
| 48 | +) |
| 49 | +def test_axis_lim_valid(df, lim): |
50 | 50 | for elem in lim:
|
51 |
| - df.plot.line(x="A", ylim=elem) |
| 51 | + df.plot.line(x="A", xlim=elem) |
0 commit comments