Skip to content

Commit c05e582

Browse files
committed
Merge branch 'main' of https://github.com/pandas-dev/pandas into factorize_na
2 parents 491a6cc + d2aa44f commit c05e582

20 files changed

+500
-125
lines changed

doc/source/whatsnew/v1.4.2.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Fixed regressions
2121
- Fixed regression in :meth:`DataFrame.replace` when a replacement value was also a target for replacement (:issue:`46306`)
2222
- Fixed regression in :meth:`DataFrame.replace` when the replacement value was explicitly ``None`` when passed in a dictionary to ``to_replace`` (:issue:`45601`, :issue:`45836`)
2323
- Fixed regression when setting values with :meth:`DataFrame.loc` losing :class:`MultiIndex` names if :class:`DataFrame` was empty before (:issue:`46317`)
24-
-
24+
- Fixed regression when rendering boolean datatype columns with :meth:`.Styler` (:issue:`46384`)
2525

2626
.. ---------------------------------------------------------------------------
2727
@@ -32,6 +32,7 @@ Bug fixes
3232
- Fix some cases for subclasses that define their ``_constructor`` properties as general callables (:issue:`46018`)
3333
- Fixed "longtable" formatting in :meth:`.Styler.to_latex` when ``column_format`` is given in extended format (:issue:`46037`)
3434
- Fixed incorrect rendering in :meth:`.Styler.format` with ``hyperlinks="html"`` when the url contains a colon or other special characters (:issue:`46389`)
35+
- Fixed :meth:`Groupby.rolling` with a frequency window that would raise a ``ValueError`` even if the datetimes within each group were monotonic (:issue:`46061`)
3536

3637
.. ---------------------------------------------------------------------------
3738

doc/source/whatsnew/v1.5.0.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,8 @@ I/O
561561
- Bug in :func:`read_parquet` when ``engine="pyarrow"`` which caused partial write to disk when column of unsupported datatype was passed (:issue:`44914`)
562562
- Bug in :func:`DataFrame.to_excel` and :class:`ExcelWriter` would raise when writing an empty DataFrame to a ``.ods`` file (:issue:`45793`)
563563
- Bug in Parquet roundtrip for Interval dtype with ``datetime64[ns]`` subtype (:issue:`45881`)
564-
- Bug in :func:`read_excel` when reading a ``.ods`` file with newlines between xml elements(:issue:`45598`)
564+
- Bug in :func:`read_excel` when reading a ``.ods`` file with newlines between xml elements (:issue:`45598`)
565+
- Bug in :func:`read_parquet` when ``engine="fastparquet"`` where the file was not closed on error (:issue:`46555`)
565566

566567
Period
567568
^^^^^^

pandas/_libs/tslibs/__init__.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@
2727
]
2828

2929
from pandas._libs.tslibs import dtypes
30-
from pandas._libs.tslibs.conversion import (
31-
OutOfBoundsTimedelta,
32-
localize_pydatetime,
33-
)
30+
from pandas._libs.tslibs.conversion import localize_pydatetime
3431
from pandas._libs.tslibs.dtypes import Resolution
3532
from pandas._libs.tslibs.nattype import (
3633
NaT,
3734
NaTType,
3835
iNaT,
3936
nat_strings,
4037
)
41-
from pandas._libs.tslibs.np_datetime import OutOfBoundsDatetime
38+
from pandas._libs.tslibs.np_datetime import (
39+
OutOfBoundsDatetime,
40+
OutOfBoundsTimedelta,
41+
)
4242
from pandas._libs.tslibs.offsets import (
4343
BaseOffset,
4444
Tick,

pandas/_libs/tslibs/conversion.pyx

+4-10
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ from pandas._libs.tslibs.np_datetime cimport (
4444
pydatetime_to_dt64,
4545
)
4646

47-
from pandas._libs.tslibs.np_datetime import OutOfBoundsDatetime
47+
from pandas._libs.tslibs.np_datetime import (
48+
OutOfBoundsDatetime,
49+
OutOfBoundsTimedelta,
50+
)
4851

4952
from pandas._libs.tslibs.timezones cimport (
5053
get_dst_info,
@@ -85,15 +88,6 @@ DT64NS_DTYPE = np.dtype('M8[ns]')
8588
TD64NS_DTYPE = np.dtype('m8[ns]')
8689

8790

88-
class OutOfBoundsTimedelta(ValueError):
89-
"""
90-
Raised when encountering a timedelta value that cannot be represented
91-
as a timedelta64[ns].
92-
"""
93-
# Timedelta analogue to OutOfBoundsDatetime
94-
pass
95-
96-
9791
# ----------------------------------------------------------------------
9892
# Unit Conversion Helpers
9993

pandas/_libs/tslibs/np_datetime.pxd

+6
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ cdef extern from "src/datetime/np_datetime.h":
6666
npy_datetime npy_datetimestruct_to_datetime(NPY_DATETIMEUNIT fr,
6767
npy_datetimestruct *d) nogil
6868

69+
void pandas_timedelta_to_timedeltastruct(npy_timedelta val,
70+
NPY_DATETIMEUNIT fr,
71+
pandas_timedeltastruct *result
72+
) nogil
6973

7074
cdef bint cmp_scalar(int64_t lhs, int64_t rhs, int op) except -1
7175

@@ -94,3 +98,5 @@ cpdef cnp.ndarray astype_overflowsafe(
9498
cnp.dtype dtype, # ndarray[datetime64[anyunit]]
9599
bint copy=*,
96100
)
101+
102+
cdef bint cmp_dtstructs(npy_datetimestruct* left, npy_datetimestruct* right, int op)

pandas/_libs/tslibs/np_datetime.pyi

+2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import numpy as np
22

33
class OutOfBoundsDatetime(ValueError): ...
4+
class OutOfBoundsTimedelta(ValueError): ...
45

56
# only exposed for testing
67
def py_get_unit_from_dtype(dtype: np.dtype): ...
8+
def py_td64_to_tdstruct(td64: int, unit: int) -> dict: ...
79
def astype_overflowsafe(
810
arr: np.ndarray, dtype: np.dtype, copy: bool = ...
911
) -> np.ndarray: ...

pandas/_libs/tslibs/np_datetime.pyx

+39-5
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ cdef extern from "src/datetime/np_datetime.h":
3434
int cmp_npy_datetimestruct(npy_datetimestruct *a,
3535
npy_datetimestruct *b)
3636

37-
void pandas_timedelta_to_timedeltastruct(npy_timedelta val,
38-
NPY_DATETIMEUNIT fr,
39-
pandas_timedeltastruct *result
40-
) nogil
41-
4237
# AS, FS, PS versions exist but are not imported because they are not used.
4338
npy_datetimestruct _NS_MIN_DTS, _NS_MAX_DTS
4439
npy_datetimestruct _US_MIN_DTS, _US_MAX_DTS
@@ -100,6 +95,28 @@ def py_get_unit_from_dtype(dtype):
10095
# Comparison
10196

10297

98+
cdef bint cmp_dtstructs(
99+
npy_datetimestruct* left, npy_datetimestruct* right, int op
100+
):
101+
cdef:
102+
int cmp_res
103+
104+
cmp_res = cmp_npy_datetimestruct(left, right)
105+
if op == Py_EQ:
106+
return cmp_res == 0
107+
if op == Py_NE:
108+
return cmp_res != 0
109+
if op == Py_GT:
110+
return cmp_res == 1
111+
if op == Py_LT:
112+
return cmp_res == -1
113+
if op == Py_GE:
114+
return cmp_res == 1 or cmp_res == 0
115+
else:
116+
# i.e. op == Py_LE
117+
return cmp_res == -1 or cmp_res == 0
118+
119+
103120
cdef inline bint cmp_scalar(int64_t lhs, int64_t rhs, int op) except -1:
104121
"""
105122
cmp_scalar is a more performant version of PyObject_RichCompare
@@ -127,6 +144,15 @@ class OutOfBoundsDatetime(ValueError):
127144
pass
128145

129146

147+
class OutOfBoundsTimedelta(ValueError):
148+
"""
149+
Raised when encountering a timedelta value that cannot be represented
150+
as a timedelta64[ns].
151+
"""
152+
# Timedelta analogue to OutOfBoundsDatetime
153+
pass
154+
155+
130156
cdef check_dts_bounds(npy_datetimestruct *dts, NPY_DATETIMEUNIT unit=NPY_FR_ns):
131157
"""Raises OutOfBoundsDatetime if the given date is outside the range that
132158
can be represented by nanosecond-resolution 64-bit integers."""
@@ -189,6 +215,14 @@ cdef inline void td64_to_tdstruct(int64_t td64,
189215
return
190216

191217

218+
# just exposed for testing at the moment
219+
def py_td64_to_tdstruct(int64_t td64, NPY_DATETIMEUNIT unit):
220+
cdef:
221+
pandas_timedeltastruct tds
222+
pandas_timedelta_to_timedeltastruct(td64, unit, &tds)
223+
return tds # <- returned as a dict to python
224+
225+
192226
cdef inline int64_t pydatetime_to_dt64(datetime val,
193227
npy_datetimestruct *dts):
194228
"""

0 commit comments

Comments
 (0)