|
10 | 10 | import pandas._testing as tm
|
11 | 11 |
|
12 | 12 |
|
13 |
| -def test_to_native_types(): |
| 13 | +def test_to_native_types_method_deprecated(): |
14 | 14 | index = pd.date_range(freq="1D", periods=3, start="2017-01-01")
|
15 |
| - |
16 |
| - # First, with no arguments. |
17 | 15 | expected = np.array(["2017-01-01", "2017-01-02", "2017-01-03"], dtype=object)
|
18 | 16 |
|
19 |
| - result = index.to_native_types() |
20 |
| - tm.assert_numpy_array_equal(result, expected) |
| 17 | + with tm.assert_produces_warning(FutureWarning): |
| 18 | + result = index.to_native_types() |
21 | 19 |
|
22 |
| - # No NaN values, so na_rep has no effect |
23 |
| - result = index.to_native_types(na_rep="pandas") |
24 | 20 | tm.assert_numpy_array_equal(result, expected)
|
25 | 21 |
|
26 | 22 | # Make sure slicing works
|
27 | 23 | expected = np.array(["2017-01-01", "2017-01-03"], dtype=object)
|
28 | 24 |
|
29 |
| - result = index.to_native_types([0, 2]) |
| 25 | + with tm.assert_produces_warning(FutureWarning): |
| 26 | + result = index.to_native_types([0, 2]) |
| 27 | + |
| 28 | + tm.assert_numpy_array_equal(result, expected) |
| 29 | + |
| 30 | + |
| 31 | +def test_to_native_types(): |
| 32 | + index = pd.date_range(freq="1D", periods=3, start="2017-01-01") |
| 33 | + |
| 34 | + # First, with no arguments. |
| 35 | + expected = np.array(["2017-01-01", "2017-01-02", "2017-01-03"], dtype=object) |
| 36 | + |
| 37 | + result = index._format_native_types() |
| 38 | + tm.assert_numpy_array_equal(result, expected) |
| 39 | + |
| 40 | + # No NaN values, so na_rep has no effect |
| 41 | + result = index._format_native_types(na_rep="pandas") |
30 | 42 | tm.assert_numpy_array_equal(result, expected)
|
31 | 43 |
|
32 | 44 | # Make sure date formatting works
|
33 | 45 | expected = np.array(["01-2017-01", "01-2017-02", "01-2017-03"], dtype=object)
|
34 | 46 |
|
35 |
| - result = index.to_native_types(date_format="%m-%Y-%d") |
| 47 | + result = index._format_native_types(date_format="%m-%Y-%d") |
36 | 48 | tm.assert_numpy_array_equal(result, expected)
|
37 | 49 |
|
38 | 50 | # NULL object handling should work
|
39 | 51 | index = DatetimeIndex(["2017-01-01", pd.NaT, "2017-01-03"])
|
40 | 52 | expected = np.array(["2017-01-01", "NaT", "2017-01-03"], dtype=object)
|
41 | 53 |
|
42 |
| - result = index.to_native_types() |
| 54 | + result = index._format_native_types() |
43 | 55 | tm.assert_numpy_array_equal(result, expected)
|
44 | 56 |
|
45 | 57 | expected = np.array(["2017-01-01", "pandas", "2017-01-03"], dtype=object)
|
46 | 58 |
|
47 |
| - result = index.to_native_types(na_rep="pandas") |
| 59 | + result = index._format_native_types(na_rep="pandas") |
48 | 60 | tm.assert_numpy_array_equal(result, expected)
|
49 | 61 |
|
50 | 62 |
|
|
0 commit comments