Skip to content

Commit d4cf1ba

Browse files
committed
Fix some imports and move whatsnew
1 parent b5b01e7 commit d4cf1ba

File tree

4 files changed

+38
-44
lines changed

4 files changed

+38
-44
lines changed

doc/source/whatsnew/v0.24.0.txt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,40 @@ that the dates have been converted to UTC
281281
.. ipython:: python
282282
pd.to_datetime(["2015-11-18 15:30:00+05:30", "2015-11-18 16:30:00+06:30"], utc=True)
283283

284+
.. _whatsnew_0240.api_breaking.period_end_time:
285+
286+
Time values in ``dt.end_time`` and ``to_timestamp(how='end')``
287+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
288+
289+
The time values in :class:`Period` and :class:`PeriodIndex` objects are now set
290+
to '23:59:59.999999999' when calling :attr:`Series.dt.end_time`, :attr:`Period.end_time`,
291+
:attr:`PeriodIndex.end_time`, :func:`Period.to_timestamp()` with ``how='end'``,
292+
or :func:`PeriodIndex.to_timestamp()` with ``how='end'`` (:issue:`17157`)
293+
294+
Previous Behavior:
295+
296+
.. code-block:: ipython
297+
298+
In [2]: p = pd.Period('2017-01-01', 'D')
299+
In [3]: pi = pd.PeriodIndex([p])
300+
301+
In [4]: pd.Series(pi).dt.end_time[0]
302+
Out[4]: Timestamp(2017-01-01 00:00:00)
303+
304+
In [5]: p.end_time
305+
Out[5]: Timestamp(2017-01-01 23:59:59.999999999)
306+
307+
Current Behavior:
308+
309+
.. ipython:: python
310+
311+
p = pd.Period('2017-01-01', 'D')
312+
pi = pd.PeriodIndex([p])
313+
314+
pd.Series(pi).dt.end_time[0]
315+
316+
p.end_time
317+
284318
.. _whatsnew_0240.api.datetimelike.normalize:
285319

286320
Tick DateOffset Normalize Restrictions

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)