(ts, values, unit)
| 2849 | |
| 2850 | |
| 2851 | def _check_temporal_rounding(ts, values, unit): |
| 2852 | unit_shorthand = { |
| 2853 | "nanosecond": "ns", |
| 2854 | "microsecond": "us", |
| 2855 | "millisecond": "ms", |
| 2856 | "second": "s", |
| 2857 | "minute": "min", |
| 2858 | "hour": "h", |
| 2859 | "day": "D" |
| 2860 | } |
| 2861 | greater_unit = { |
| 2862 | "nanosecond": "us", |
| 2863 | "microsecond": "ms", |
| 2864 | "millisecond": "s", |
| 2865 | "second": "min", |
| 2866 | "minute": "h", |
| 2867 | "hour": "D", |
| 2868 | } |
| 2869 | ta = pa.array(ts) |
| 2870 | |
| 2871 | for value in values: |
| 2872 | frequency = str(value) + unit_shorthand[unit] |
| 2873 | options = pc.RoundTemporalOptions(value, unit) |
| 2874 | |
| 2875 | result = pc.ceil_temporal(ta, options=options).to_pandas() |
| 2876 | expected = ts.dt.ceil(frequency) |
| 2877 | np.testing.assert_array_equal(result, expected) |
| 2878 | |
| 2879 | result = pc.floor_temporal(ta, options=options).to_pandas() |
| 2880 | expected = ts.dt.floor(frequency) |
| 2881 | np.testing.assert_array_equal(result, expected) |
| 2882 | |
| 2883 | result = pc.round_temporal(ta, options=options).to_pandas() |
| 2884 | expected = ts.dt.round(frequency) |
| 2885 | np.testing.assert_array_equal(result, expected) |
| 2886 | |
| 2887 | # Check rounding with calendar_based_origin=True. |
| 2888 | # Note: rounding to month is not supported in Pandas so we can't |
| 2889 | # approximate this functionality and exclude unit == "day". |
| 2890 | if unit != "day": |
| 2891 | options = pc.RoundTemporalOptions( |
| 2892 | value, unit, calendar_based_origin=True) |
| 2893 | origin = ts.dt.floor(greater_unit[unit]) |
| 2894 | |
| 2895 | if ta.type.tz is None: |
| 2896 | result = pc.ceil_temporal(ta, options=options).to_pandas() |
| 2897 | expected = (ts - origin).dt.ceil(frequency) + origin |
| 2898 | np.testing.assert_array_equal(result, expected) |
| 2899 | |
| 2900 | result = pc.floor_temporal(ta, options=options).to_pandas() |
| 2901 | expected = (ts - origin).dt.floor(frequency) + origin |
| 2902 | np.testing.assert_array_equal(result, expected) |
| 2903 | |
| 2904 | result = pc.round_temporal(ta, options=options).to_pandas() |
| 2905 | expected = (ts - origin).dt.round(frequency) + origin |
| 2906 | np.testing.assert_array_equal(result, expected) |
| 2907 | |
| 2908 | # Check RoundTemporalOptions partial defaults |
no test coverage detected