Skip to content

Commit c1f4194

Browse files
authored
Merge branch 'master' into na_option_handle
2 parents d0d3e73 + 57c7daa commit c1f4194

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1686
-1092
lines changed

doc/source/whatsnew/v0.24.0.txt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,43 @@ 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+
Calling :attr:`Series.dt.end_time` will now result in a time of '23:59:59.999999999' as
310+
is the case with :attr:`Period.end_time`, for example
311+
312+
.. ipython:: python
313+
314+
p = pd.Period('2017-01-01', 'D')
315+
pi = pd.PeriodIndex([p])
316+
317+
pd.Series(pi).dt.end_time[0]
318+
319+
p.end_time
320+
284321
.. _whatsnew_0240.api.datetimelike.normalize:
285322

286323
Tick DateOffset Normalize Restrictions
@@ -615,6 +652,7 @@ Reshaping
615652
- Bug in :meth:`Series.combine_first` with ``datetime64[ns, tz]`` dtype which would return tz-naive result (:issue:`21469`)
616653
- Bug in :meth:`Series.where` and :meth:`DataFrame.where` with ``datetime64[ns, tz]`` dtype (:issue:`21546`)
617654
- Bug in :meth:`Series.mask` and :meth:`DataFrame.mask` with ``list`` conditionals (:issue:`21891`)
655+
- Bug in :meth:`DataFrame.replace` raises RecursionError when converting OutOfBounds ``datetime64[ns, tz]`` (:issue:`20380`)
618656
- :func:`pandas.core.groupby.GroupBy.rank` now raises a ``ValueError`` when an invalid value is passed for argument ``na_option`` (:issue:`22124`)
619657
-
620658

pandas/_libs/algos.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def is_lexsorted(list list_of_arrays):
129129
for i in range(nlevels):
130130
arr = list_of_arrays[i]
131131
assert arr.dtype.name == 'int64'
132-
vecs[i] = <int64_t*> arr.data
132+
vecs[i] = <int64_t*> cnp.PyArray_DATA(arr)
133133

134134
# Assume uniqueness??
135135
with nogil:

pandas/_libs/groupby.pyx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ from cython cimport Py_ssize_t
77
from libc.stdlib cimport malloc, free
88

99
import numpy as np
10+
cimport numpy as cnp
1011
from numpy cimport (ndarray,
1112
double_t,
1213
int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t,
1314
uint32_t, uint64_t, float32_t, float64_t)
15+
cnp.import_array()
1416

1517

1618
from util cimport numeric, get_nat
@@ -118,7 +120,7 @@ def group_median_float64(ndarray[float64_t, ndim=2] out,
118120
counts[:] = _counts[1:]
119121

120122
data = np.empty((K, N), dtype=np.float64)
121-
ptr = <float64_t*> data.data
123+
ptr = <float64_t*> cnp.PyArray_DATA(data)
122124

123125
take_2d_axis1_float64_float64(values.T, indexer, out=data)
124126

pandas/_libs/index.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ cdef inline bint is_definitely_invalid_key(object val):
3737
return True
3838

3939
# we have a _data, means we are a NDFrame
40-
return (PySlice_Check(val) or cnp.PyArray_Check(val)
40+
return (PySlice_Check(val) or util.is_array(val)
4141
or PyList_Check(val) or hasattr(val, '_data'))
4242

4343

@@ -104,7 +104,7 @@ cdef class IndexEngine:
104104
void* data_ptr
105105

106106
loc = self.get_loc(key)
107-
if PySlice_Check(loc) or cnp.PyArray_Check(loc):
107+
if PySlice_Check(loc) or util.is_array(loc):
108108
return arr[loc]
109109
else:
110110
return get_value_at(arr, loc, tz=tz)
@@ -120,7 +120,7 @@ cdef class IndexEngine:
120120
loc = self.get_loc(key)
121121
value = convert_scalar(arr, value)
122122

123-
if PySlice_Check(loc) or cnp.PyArray_Check(loc):
123+
if PySlice_Check(loc) or util.is_array(loc):
124124
arr[loc] = value
125125
else:
126126
util.set_value_at(arr, loc, value)

pandas/_libs/src/numpy_helper.h

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ The full license is in the LICENSE file, distributed with this software.
1616
#include "numpy/arrayscalars.h"
1717

1818

19-
PANDAS_INLINE npy_int64 get_nat(void) { return NPY_MIN_INT64; }
20-
2119
PANDAS_INLINE int assign_value_1d(PyArrayObject* ap, Py_ssize_t _i,
2220
PyObject* v) {
2321
npy_intp i = (npy_intp)_i;
@@ -40,16 +38,10 @@ PANDAS_INLINE const char* get_c_string(PyObject* obj) {
4038
#endif
4139
}
4240

43-
PANDAS_INLINE PyObject* char_to_string(const char* data) {
44-
#if PY_VERSION_HEX >= 0x03000000
45-
return PyUnicode_FromString(data);
46-
#else
47-
return PyString_FromString(data);
48-
#endif
49-
}
50-
5141
void set_array_not_contiguous(PyArrayObject* ao) {
52-
ao->flags &= ~(NPY_ARRAY_C_CONTIGUOUS | NPY_ARRAY_F_CONTIGUOUS);
42+
// Numpy>=1.8-compliant equivalent to:
43+
// ao->flags &= ~(NPY_ARRAY_C_CONTIGUOUS | NPY_ARRAY_F_CONTIGUOUS);
44+
PyArray_CLEARFLAGS(ao, (NPY_ARRAY_C_CONTIGUOUS | NPY_ARRAY_F_CONTIGUOUS));
5345
}
5446

5547
#endif // PANDAS__LIBS_SRC_NUMPY_HELPER_H_

pandas/_libs/tslibs/conversion.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,7 @@ def tz_localize_to_utc(ndarray[int64_t] vals, object tz, object ambiguous=None,
888888

889889
trans, deltas, typ = get_dst_info(tz)
890890

891-
tdata = <int64_t*> trans.data
891+
tdata = <int64_t*> cnp.PyArray_DATA(trans)
892892
ntrans = len(trans)
893893

894894
result_a = np.empty(n, dtype=np.int64)

pandas/_libs/tslibs/period.pyx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +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.tslibs.timedeltas import Timedelta
3738
from timestamps import Timestamp
3839
from timezones cimport is_utc, is_tzlocal, get_dst_info
3940
from timedeltas cimport delta_to_nanoseconds
@@ -1221,6 +1222,10 @@ cdef class _Period(object):
12211222
freq = self._maybe_convert_freq(freq)
12221223
how = _validate_end_alias(how)
12231224

1225+
end = how == 'E'
1226+
if end:
1227+
return (self + 1).to_timestamp(how='start') - Timedelta(1, 'ns')
1228+
12241229
if freq is None:
12251230
base, mult = get_freq_code(self.freq)
12261231
freq = get_to_timestamp_base(base)

0 commit comments

Comments
 (0)