|
6 | 6 |
|
7 | 7 | from pandas._libs.tslibs import iNaT, period as libperiod
|
8 | 8 | from pandas._libs.tslibs.ccalendar import DAYS, MONTHS
|
| 9 | +from pandas._libs.tslibs.np_datetime import OutOfBoundsDatetime |
9 | 10 | from pandas._libs.tslibs.parsing import DateParseError
|
10 | 11 | from pandas._libs.tslibs.period import INVALID_FREQ_ERR_MSG, IncompatibleFrequency
|
11 | 12 | from pandas._libs.tslibs.timezones import dateutil_gettz, maybe_get_tz
|
@@ -776,6 +777,35 @@ def test_period_deprecated_freq(self):
|
776 | 777 | assert isinstance(p1, Period)
|
777 | 778 | assert isinstance(p2, Period)
|
778 | 779 |
|
| 780 | + def _period_constructor(bound, offset): |
| 781 | + return Period( |
| 782 | + year=bound.year, |
| 783 | + month=bound.month, |
| 784 | + day=bound.day, |
| 785 | + hour=bound.hour, |
| 786 | + minute=bound.minute, |
| 787 | + second=bound.second + offset, |
| 788 | + freq="us", |
| 789 | + ) |
| 790 | + |
| 791 | + @pytest.mark.parametrize("bound, offset", [(Timestamp.min, -1), (Timestamp.max, 1)]) |
| 792 | + @pytest.mark.parametrize("period_property", ["start_time", "end_time"]) |
| 793 | + def test_outter_bounds_start_and_end_time(self, bound, offset, period_property): |
| 794 | + # GH #13346 |
| 795 | + period = TestPeriodProperties._period_constructor(bound, offset) |
| 796 | + with pytest.raises(OutOfBoundsDatetime, match="Out of bounds nanosecond"): |
| 797 | + getattr(period, period_property) |
| 798 | + |
| 799 | + @pytest.mark.parametrize("bound, offset", [(Timestamp.min, -1), (Timestamp.max, 1)]) |
| 800 | + @pytest.mark.parametrize("period_property", ["start_time", "end_time"]) |
| 801 | + def test_inner_bounds_start_and_end_time(self, bound, offset, period_property): |
| 802 | + # GH #13346 |
| 803 | + period = TestPeriodProperties._period_constructor(bound, -offset) |
| 804 | + expected = period.to_timestamp().round(freq="S") |
| 805 | + assert getattr(period, period_property).round(freq="S") == expected |
| 806 | + expected = (bound - offset * Timedelta(1, unit="S")).floor("S") |
| 807 | + assert getattr(period, period_property).floor("S") == expected |
| 808 | + |
779 | 809 | def test_start_time(self):
|
780 | 810 | freq_lst = ["A", "Q", "M", "D", "H", "T", "S"]
|
781 | 811 | xp = datetime(2012, 1, 1)
|
|
0 commit comments