| 2909 | |
| 2910 | @pytest.mark.pandas |
| 2911 | def test_interval_array_from_dateoffset(): |
| 2912 | from pandas.tseries.offsets import DateOffset |
| 2913 | data = [ |
| 2914 | None, |
| 2915 | DateOffset(years=1, months=1, |
| 2916 | days=1, seconds=1, microseconds=1, |
| 2917 | minutes=1, hours=1, weeks=1, nanoseconds=1), |
| 2918 | DateOffset()] |
| 2919 | |
| 2920 | arr = pa.array(data) |
| 2921 | assert isinstance(arr, pa.MonthDayNanoIntervalArray) |
| 2922 | assert arr.type == pa.month_day_nano_interval() |
| 2923 | expected_list = [ |
| 2924 | None, |
| 2925 | pa.MonthDayNano([13, 8, 3661000001001]), |
| 2926 | pa.MonthDayNano([0, 0, 0])] |
| 2927 | expected = pa.array(expected_list) |
| 2928 | assert arr.equals(expected) |
| 2929 | expected_from_pandas = [ |
| 2930 | None, DateOffset(months=13, days=8, |
| 2931 | nanoseconds=( |
| 2932 | datetime.timedelta(seconds=1, microseconds=1, |
| 2933 | minutes=1, hours=1) // |
| 2934 | datetime.timedelta(microseconds=1) * 1000) + 1), |
| 2935 | DateOffset(months=0, days=0, nanoseconds=0)] |
| 2936 | |
| 2937 | assert arr.to_pandas().tolist() == expected_from_pandas |
| 2938 | |
| 2939 | # nested list<interval> array conversion |
| 2940 | actual_list = pa.array([data]).to_pandas().tolist() |
| 2941 | assert len(actual_list) == 1 |
| 2942 | assert list(actual_list[0]) == expected_from_pandas |
| 2943 | |
| 2944 | |
| 2945 | @pytest.mark.numpy |