Skip to content

Commit 99e1fc2

Browse files
committed
Fix some imports and move whatsnew
1 parent ee987cb commit 99e1fc2

File tree

4 files changed

+37
-44
lines changed

4 files changed

+37
-44
lines changed

doc/source/whatsnew/v0.24.0.txt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,39 @@ For situations where you need an ``ndarray`` of ``Interval`` objects, use
224224
np.asarray(idx)
225225
idx.values.astype(object)
226226

227+
.. _whatsnew_0240.api_breaking.period_end_time:
228+
229+
Time values in ``dt.end_time`` and ``to_timestamp(how='end')``
230+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
231+
232+
The time values in :class:`Period` and :class:`PeriodIndex` objects are now set
233+
to '23:59:59.999999999' when calling :attr:`Series.dt.end_time`, :attr:`Period.end_time`,
234+
:attr:`PeriodIndex.end_time`, :func:`Period.to_timestamp()` with ``how='end'``,
235+
or :func:`PeriodIndex.to_timestamp()` with ``how='end'`` (:issue:`17157`)
236+
237+
Previous Behavior:
238+
239+
.. code-block:: ipython
240+
241+
In [2]: p = pd.Period('2017-01-01', 'D')
242+
In [3]: pi = pd.PeriodIndex([p])
243+
244+
In [4]: pd.Series(pi).dt.end_time[0]
245+
Out[4]: Timestamp(2017-01-01 00:00:00)
246+
247+
In [5]: p.end_time
248+
Out[5]: Timestamp(2017-01-01 23:59:59.999999999)
249+
250+
Current Behavior:
251+
252+
.. ipython:: python
253+
254+
p = pd.Period('2017-01-01', 'D')
255+
pi = pd.PeriodIndex([p])
256+
257+
pd.Series(pi).dt.end_time[0]
258+
259+
p.end_time
227260

228261
.. _whatsnew_0240.api.datetimelike.normalize:
229262

pandas/_libs/tslibs/period.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
# cython: profile=False
3-
from datetime import datetime, date, timedelta
3+
from datetime import datetime, date
44

55
from cpython cimport (
66
PyUnicode_Check,
@@ -34,7 +34,7 @@ cdef extern from "../src/datetime/np_datetime.h":
3434
cimport util
3535
from util cimport is_period_object, is_string_object, INT32_MIN
3636

37-
from pandas._libs.tslib import Timedelta
37+
from pandas._libs.tslibs.timedeltas import Timedelta
3838
from timestamps import Timestamp
3939
from timezones cimport is_utc, is_tzlocal, get_dst_info
4040
from timedeltas cimport delta_to_nanoseconds

pandas/core/indexes/datetimes.py

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,47 +1566,6 @@ def to_julian_date(self):
15661566
DatetimeIndex._add_datetimelike_methods()
15671567

15681568

1569-
<<<<<<< 52e0171b2086c87362ae33db0d3fe9cc2c4afc2a
1570-
=======
1571-
def _generate_regular_range(cls, start, end, periods, freq):
1572-
if isinstance(freq, Tick):
1573-
stride = freq.nanos
1574-
if periods is None:
1575-
b = Timestamp(start).value
1576-
# cannot just use e = Timestamp(end) + 1 because arange breaks when
1577-
# stride is too large, see GH10887
1578-
e = (b + (Timestamp(end).value - b) // stride * stride +
1579-
stride // 2 + 1)
1580-
# end.tz == start.tz by this point due to _generate implementation
1581-
tz = start.tz
1582-
elif start is not None:
1583-
b = Timestamp(start).value
1584-
e = b + np.int64(periods) * stride
1585-
tz = start.tz
1586-
elif end is not None:
1587-
e = Timestamp(end).value + stride
1588-
b = e - np.int64(periods) * stride
1589-
tz = end.tz
1590-
else:
1591-
raise ValueError("at least 'start' or 'end' should be specified "
1592-
"if a 'period' is given.")
1593-
1594-
data = np.arange(b, e, stride, dtype=np.int64)
1595-
# TODO: Do we need to use _simple_new here? just return data.view?
1596-
data = cls._simple_new(data.view(_NS_DTYPE), None, tz=tz)
1597-
else:
1598-
1599-
xdr = generate_range(start=start, end=end,
1600-
periods=periods, offset=offset)
1601-
1602-
dates = list(xdr)
1603-
# utc = len(dates) > 0 and dates[0].tzinfo is not None
1604-
data = tools.to_datetime(dates)
1605-
1606-
return data
1607-
1608-
1609-
>>>>>>> simplify timestamp precision issue
16101569
def date_range(start=None, end=None, periods=None, freq=None, tz=None,
16111570
normalize=False, name=None, closed=None, **kwargs):
16121571
"""

pandas/core/indexes/period.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from pandas.core.tools.datetimes import parse_time_string
2626

2727
from pandas._libs.lib import infer_dtype
28-
from pandas._libs import tslib, index as libindex
28+
from pandas._libs import tslib, index as libindex, Timedelta
2929
from pandas._libs.tslibs.period import (Period, IncompatibleFrequency,
3030
DIFFERENT_FREQ_INDEX,
3131
_validate_end_alias)
@@ -504,6 +504,7 @@ def to_timestamp(self, freq=None, how='start'):
504504
end = how == 'E'
505505
if end:
506506
if freq == 'B':
507+
# roll forward to ensure we land on B date
507508
adjust = Timedelta(1, 'D') - Timedelta(1, 'ns')
508509
return self.to_timestamp(how='start') + adjust
509510
else:

0 commit comments

Comments
 (0)