| 2853 | |
| 2854 | @pytest.mark.pandas |
| 2855 | def test_interval_array_from_relativedelta(): |
| 2856 | # dateutil is dependency of pandas |
| 2857 | from dateutil.relativedelta import relativedelta |
| 2858 | from pandas import DateOffset |
| 2859 | data = [ |
| 2860 | None, |
| 2861 | relativedelta(years=1, months=1, |
| 2862 | days=1, seconds=1, microseconds=1, |
| 2863 | minutes=1, hours=1, weeks=1, leapdays=1)] |
| 2864 | # Note leapdays are ignored. |
| 2865 | |
| 2866 | # From relativedelta |
| 2867 | arr = pa.array(data) |
| 2868 | assert isinstance(arr, pa.MonthDayNanoIntervalArray) |
| 2869 | assert arr.type == pa.month_day_nano_interval() |
| 2870 | expected_list = [ |
| 2871 | None, |
| 2872 | pa.MonthDayNano([13, 8, |
| 2873 | (datetime.timedelta(seconds=1, microseconds=1, |
| 2874 | minutes=1, hours=1) // |
| 2875 | datetime.timedelta(microseconds=1)) * 1000])] |
| 2876 | expected = pa.array(expected_list) |
| 2877 | assert arr.equals(expected) |
| 2878 | assert arr.to_pandas().tolist() == [ |
| 2879 | None, DateOffset(months=13, days=8, |
| 2880 | nanoseconds=( |
| 2881 | datetime.timedelta(seconds=1, microseconds=1, |
| 2882 | minutes=1, hours=1) // |
| 2883 | datetime.timedelta(microseconds=1)) * 1000)] |
| 2884 | with pytest.raises(ValueError): |
| 2885 | pa.array([DateOffset(years=((1 << 32) // 12), months=100)]) |
| 2886 | with pytest.raises(ValueError): |
| 2887 | pa.array([DateOffset(weeks=((1 << 32) // 7), days=100)]) |
| 2888 | with pytest.raises(ValueError): |
| 2889 | pa.array([DateOffset(seconds=((1 << 64) // 1000000000), |
| 2890 | nanoseconds=1)]) |
| 2891 | with pytest.raises(ValueError): |
| 2892 | pa.array([DateOffset(microseconds=((1 << 64) // 100))]) |
| 2893 | |
| 2894 | |
| 2895 | def test_interval_array_from_tuple(): |