|
12 | 12 | import pytz
|
13 | 13 |
|
14 | 14 | from pandas._libs.tslibs.timezones import maybe_get_tz
|
| 15 | +from pandas.compat import pa_version_under7p0 |
15 | 16 | from pandas.errors import SettingWithCopyError
|
16 | 17 |
|
17 | 18 | from pandas.core.dtypes.common import (
|
@@ -89,8 +90,15 @@ def get_expected(ser, prop):
|
89 | 90 | return result
|
90 | 91 | return Series(result, index=ser.index, name=ser.name, dtype=result.dtype)
|
91 | 92 |
|
92 |
| - left = getattr(ser.dt, name) |
93 |
| - right = get_expected(ser, name) |
| 93 | + if name == "time": |
| 94 | + msg = "In a future version, this will an array with pyarrow time dtype" |
| 95 | + with tm.assert_produces_warning(FutureWarning, match=msg): |
| 96 | + left = getattr(ser.dt, name) |
| 97 | + right = get_expected(ser, name) |
| 98 | + else: |
| 99 | + left = getattr(ser.dt, name) |
| 100 | + right = get_expected(ser, name) |
| 101 | + |
94 | 102 | if not (is_list_like(left) and is_list_like(right)):
|
95 | 103 | assert left == right
|
96 | 104 | elif isinstance(left, DataFrame):
|
@@ -672,10 +680,31 @@ def test_valid_dt_with_missing_values(self):
|
672 | 680 | )
|
673 | 681 | tm.assert_series_equal(result, expected)
|
674 | 682 |
|
675 |
| - result = ser.dt.time |
| 683 | + msg = "In a future version, this will an array with pyarrow time" |
| 684 | + with tm.assert_produces_warning(FutureWarning, match=msg): |
| 685 | + result = ser.dt.time |
676 | 686 | expected = Series([time(0), time(0), np.nan, time(0), time(0)], dtype="object")
|
677 | 687 | tm.assert_series_equal(result, expected)
|
678 | 688 |
|
| 689 | + with pd.option_context("future.infer_time", False): |
| 690 | + with tm.assert_produces_warning(None): |
| 691 | + result = ser.dt.time |
| 692 | + tm.assert_series_equal(result, expected) |
| 693 | + |
| 694 | + if pa_version_under7p0: |
| 695 | + return |
| 696 | + |
| 697 | + with pd.option_context("future.infer_time", True): |
| 698 | + with tm.assert_produces_warning(None): |
| 699 | + result_pa = ser.dt.time |
| 700 | + |
| 701 | + import pyarrow as pa |
| 702 | + |
| 703 | + pa_dtype = pa.time64("ns") |
| 704 | + dtype = pd.ArrowDtype(pa_dtype) |
| 705 | + expected_pa = expected.astype(dtype) |
| 706 | + tm.assert_series_equal(result_pa, expected_pa) |
| 707 | + |
679 | 708 | def test_dt_accessor_api(self):
|
680 | 709 | # GH 9322
|
681 | 710 | from pandas.core.indexes.accessors import (
|
|
0 commit comments