|
1 | 1 | import numpy as np
|
| 2 | +import pytest |
2 | 3 |
|
3 | 4 | from pandas._libs.tslibs import fields
|
4 | 5 |
|
5 | 6 | import pandas._testing as tm
|
6 | 7 |
|
7 | 8 |
|
8 |
| -def test_fields_readonly(): |
9 |
| - # https://github.com/vaexio/vaex/issues/357 |
10 |
| - # fields functions shouldn't raise when we pass read-only data |
| 9 | +@pytest.fixture |
| 10 | +def dtindex(): |
11 | 11 | dtindex = np.arange(5, dtype=np.int64) * 10 ** 9 * 3600 * 24 * 32
|
12 | 12 | dtindex.flags.writeable = False
|
| 13 | + return dtindex |
13 | 14 |
|
| 15 | + |
| 16 | +def test_get_date_name_field_readonly(dtindex): |
| 17 | + # https://github.com/vaexio/vaex/issues/357 |
| 18 | + # fields functions shouldn't raise when we pass read-only data |
14 | 19 | result = fields.get_date_name_field(dtindex, "month_name")
|
15 | 20 | expected = np.array(["January", "February", "March", "April", "May"], dtype=object)
|
16 | 21 | tm.assert_numpy_array_equal(result, expected)
|
17 | 22 |
|
| 23 | + |
| 24 | +def test_get_date_field_readonly(dtindex): |
18 | 25 | result = fields.get_date_field(dtindex, "Y")
|
19 | 26 | expected = np.array([1970, 1970, 1970, 1970, 1970], dtype=np.int32)
|
20 | 27 | tm.assert_numpy_array_equal(result, expected)
|
21 | 28 |
|
| 29 | + |
| 30 | +def test_get_start_end_field_readonly(dtindex): |
22 | 31 | result = fields.get_start_end_field(dtindex, "is_month_start", None)
|
23 | 32 | expected = np.array([True, False, False, False, False], dtype=np.bool_)
|
24 | 33 | tm.assert_numpy_array_equal(result, expected)
|
25 | 34 |
|
| 35 | + |
| 36 | +def test_get_timedelta_field_readonly(dtindex): |
26 | 37 | # treat dtindex as timedeltas for this next one
|
27 | 38 | result = fields.get_timedelta_field(dtindex, "days")
|
28 | 39 | expected = np.arange(5, dtype=np.int32) * 32
|
|
0 commit comments