Skip to content

Commit 7f2e1c8

Browse files
committed
Merge branch 'main' into tst-str-gb
2 parents 9b53a14 + 1044cf4 commit 7f2e1c8

File tree

17 files changed

+843
-115
lines changed

17 files changed

+843
-115
lines changed

.github/actions/build_pandas/action.yml

+7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ runs:
2222
fi
2323
shell: bash -el {0}
2424

25+
- name: Uninstall nomkl
26+
run: |
27+
if conda list nomkl | grep nomkl 1>/dev/null; then
28+
conda remove nomkl -y
29+
fi
30+
shell: bash -el {0}
31+
2532
- name: Build Pandas
2633
run: |
2734
if [[ ${{ inputs.editable }} == "true" ]]; then

.pre-commit-config.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ repos:
2323
hooks:
2424
- id: ruff
2525
args: [--exit-non-zero-on-fix]
26+
exclude: ^pandas/tests/frame/test_query_eval.py
2627
- id: ruff
2728
# TODO: remove autofixe-only rules when they are checked by ruff
2829
name: ruff-selected-autofixes
@@ -31,7 +32,7 @@ repos:
3132
exclude: ^pandas/tests
3233
args: [--select, "ANN001,ANN2", --fix-only, --exit-non-zero-on-fix]
3334
- id: ruff-format
34-
exclude: ^scripts
35+
exclude: ^scripts|^pandas/tests/frame/test_query_eval.py
3536
- repo: https://github.com/jendrikseipp/vulture
3637
rev: 'v2.11'
3738
hooks:
@@ -85,6 +86,7 @@ repos:
8586
types: [text] # overwrite types: [rst]
8687
types_or: [python, rst]
8788
- id: rst-inline-touching-normal
89+
exclude: ^pandas/tests/frame/test_query_eval.py
8890
types: [text] # overwrite types: [rst]
8991
types_or: [python, rst]
9092
- repo: https://github.com/sphinx-contrib/sphinx-lint

ci/code_checks.sh

-21
Original file line numberDiff line numberDiff line change
@@ -180,36 +180,20 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
180180
-i "pandas.TimedeltaIndex.nanoseconds SA01" \
181181
-i "pandas.TimedeltaIndex.seconds SA01" \
182182
-i "pandas.TimedeltaIndex.to_pytimedelta RT03,SA01" \
183-
-i "pandas.Timestamp.combine PR01,SA01" \
184-
-i "pandas.Timestamp.ctime SA01" \
185-
-i "pandas.Timestamp.date SA01" \
186183
-i "pandas.Timestamp.day GL08" \
187184
-i "pandas.Timestamp.fold GL08" \
188-
-i "pandas.Timestamp.fromordinal SA01" \
189-
-i "pandas.Timestamp.fromtimestamp PR01,SA01" \
190185
-i "pandas.Timestamp.hour GL08" \
191186
-i "pandas.Timestamp.max PR02" \
192187
-i "pandas.Timestamp.microsecond GL08" \
193188
-i "pandas.Timestamp.min PR02" \
194189
-i "pandas.Timestamp.minute GL08" \
195190
-i "pandas.Timestamp.month GL08" \
196-
-i "pandas.Timestamp.month_name SA01" \
197191
-i "pandas.Timestamp.nanosecond GL08" \
198-
-i "pandas.Timestamp.normalize SA01" \
199-
-i "pandas.Timestamp.quarter SA01" \
200-
-i "pandas.Timestamp.replace PR07,SA01" \
201192
-i "pandas.Timestamp.resolution PR02" \
202193
-i "pandas.Timestamp.second GL08" \
203194
-i "pandas.Timestamp.strptime PR01,SA01" \
204-
-i "pandas.Timestamp.timestamp SA01" \
205-
-i "pandas.Timestamp.timetuple SA01" \
206195
-i "pandas.Timestamp.timetz SA01" \
207196
-i "pandas.Timestamp.to_datetime64 SA01" \
208-
-i "pandas.Timestamp.to_julian_date SA01" \
209-
-i "pandas.Timestamp.to_numpy PR01" \
210-
-i "pandas.Timestamp.to_period PR01,SA01" \
211-
-i "pandas.Timestamp.today SA01" \
212-
-i "pandas.Timestamp.toordinal SA01" \
213197
-i "pandas.Timestamp.tzinfo GL08" \
214198
-i "pandas.Timestamp.value GL08" \
215199
-i "pandas.Timestamp.year GL08" \
@@ -224,11 +208,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
224208
-i "pandas.api.extensions.ExtensionArray.insert PR07,RT03,SA01" \
225209
-i "pandas.api.extensions.ExtensionArray.interpolate PR01,SA01" \
226210
-i "pandas.api.extensions.ExtensionArray.isin PR07,RT03,SA01" \
227-
-i "pandas.api.extensions.ExtensionArray.isna SA01" \
228-
-i "pandas.api.extensions.ExtensionArray.nbytes SA01" \
229-
-i "pandas.api.extensions.ExtensionArray.ndim SA01" \
230-
-i "pandas.api.extensions.ExtensionArray.ravel RT03,SA01" \
231-
-i "pandas.api.extensions.ExtensionArray.take RT03" \
232211
-i "pandas.api.extensions.ExtensionArray.tolist RT03,SA01" \
233212
-i "pandas.api.extensions.ExtensionArray.unique RT03,SA01" \
234213
-i "pandas.api.extensions.ExtensionArray.view SA01" \

doc/source/whatsnew/v3.0.0.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ Datetimelike
543543
- Bug in :attr:`is_year_start` where a DateTimeIndex constructed via a date_range with frequency 'MS' wouldn't have the correct year or quarter start attributes (:issue:`57377`)
544544
- Bug in :class:`Timestamp` constructor failing to raise when ``tz=None`` is explicitly specified in conjunction with timezone-aware ``tzinfo`` or data (:issue:`48688`)
545545
- Bug in :func:`date_range` where the last valid timestamp would sometimes not be produced (:issue:`56134`)
546-
- Bug in :func:`date_range` where using a negative frequency value would not include all points between the start and end values (:issue:`56382`)
546+
- Bug in :func:`date_range` where using a negative frequency value would not include all points between the start and end values (:issue:`56147`)
547547
- Bug in :func:`tseries.api.guess_datetime_format` would fail to infer time format when "%Y" == "%H%M" (:issue:`57452`)
548548
- Bug in :func:`tseries.frequencies.to_offset` would fail to parse frequency strings starting with "LWOM" (:issue:`59218`)
549549
- Bug in :meth:`Dataframe.agg` with df with missing values resulting in IndexError (:issue:`58810`)
@@ -685,6 +685,7 @@ Other
685685
- Bug in :meth:`DataFrame.apply` where passing ``engine="numba"`` ignored ``args`` passed to the applied function (:issue:`58712`)
686686
- Bug in :meth:`DataFrame.eval` and :meth:`DataFrame.query` which caused an exception when using NumPy attributes via ``@`` notation, e.g., ``df.eval("@np.floor(a)")``. (:issue:`58041`)
687687
- Bug in :meth:`DataFrame.eval` and :meth:`DataFrame.query` which did not allow to use ``tan`` function. (:issue:`55091`)
688+
- Bug in :meth:`DataFrame.query` which raised an exception or produced incorrect results when expressions contained backtick-quoted column names containing the hash character ``#``, backticks, or characters that fall outside the ASCII range (U+0001..U+007F). (:issue:`59285`) (:issue:`49633`)
688689
- Bug in :meth:`DataFrame.sort_index` when passing ``axis="columns"`` and ``ignore_index=True`` and ``ascending=False`` not returning a :class:`RangeIndex` columns (:issue:`57293`)
689690
- Bug in :meth:`DataFrame.transform` that was returning the wrong order unless the index was monotonically increasing. (:issue:`57069`)
690691
- Bug in :meth:`DataFrame.where` where using a non-bool type array in the function would return a ``ValueError`` instead of a ``TypeError`` (:issue:`56330`)

pandas/_libs/src/vendored/numpy/datetime/np_datetime.c

+29-19
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,12 @@ This file is derived from NumPy 1.7. See NUMPY_LICENSE.txt
2020
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
2121
#endif // NPY_NO_DEPRECATED_API
2222

23-
#include <Python.h>
24-
2523
#include "pandas/vendored/numpy/datetime/np_datetime.h"
26-
2724
#define NO_IMPORT_ARRAY
2825
#define PY_ARRAY_UNIQUE_SYMBOL PANDAS_DATETIME_NUMPY
2926
#include <numpy/ndarrayobject.h>
3027
#include <numpy/npy_common.h>
28+
#include <stdbool.h>
3129

3230
#if defined(_WIN32)
3331
#ifndef ENABLE_INTSAFE_SIGNED_FUNCTIONS
@@ -58,12 +56,15 @@ _Static_assert(0, "__has_builtin not detected; please try a newer compiler");
5856
#endif
5957
#endif
6058

59+
#define XSTR(a) STR(a)
60+
#define STR(a) #a
61+
6162
#define PD_CHECK_OVERFLOW(FUNC) \
6263
do { \
6364
if ((FUNC) != 0) { \
6465
PyGILState_STATE gstate = PyGILState_Ensure(); \
6566
PyErr_SetString(PyExc_OverflowError, \
66-
"Overflow occurred in npy_datetimestruct_to_datetime"); \
67+
"Overflow occurred at " __FILE__ ":" XSTR(__LINE__)); \
6768
PyGILState_Release(gstate); \
6869
return -1; \
6970
} \
@@ -139,53 +140,53 @@ npy_int64 get_datetimestruct_days(const npy_datetimestruct *dts) {
139140
npy_int64 year, days = 0;
140141
const int *month_lengths;
141142

142-
year = dts->year - 1970;
143-
days = year * 365;
143+
PD_CHECK_OVERFLOW(checked_int64_sub(dts->year, 1970, &year));
144+
PD_CHECK_OVERFLOW(checked_int64_mul(year, 365, &days));
144145

145146
/* Adjust for leap years */
146147
if (days >= 0) {
147148
/*
148149
* 1968 is the closest leap year before 1970.
149150
* Exclude the current year, so add 1.
150151
*/
151-
year += 1;
152+
PD_CHECK_OVERFLOW(checked_int64_add(year, 1, &year));
152153
/* Add one day for each 4 years */
153-
days += year / 4;
154+
PD_CHECK_OVERFLOW(checked_int64_add(days, year / 4, &days));
154155
/* 1900 is the closest previous year divisible by 100 */
155-
year += 68;
156+
PD_CHECK_OVERFLOW(checked_int64_add(year, 68, &year));
156157
/* Subtract one day for each 100 years */
157-
days -= year / 100;
158+
PD_CHECK_OVERFLOW(checked_int64_sub(days, year / 100, &days));
158159
/* 1600 is the closest previous year divisible by 400 */
159-
year += 300;
160+
PD_CHECK_OVERFLOW(checked_int64_add(year, 300, &year));
160161
/* Add one day for each 400 years */
161-
days += year / 400;
162+
PD_CHECK_OVERFLOW(checked_int64_add(days, year / 400, &days));
162163
} else {
163164
/*
164165
* 1972 is the closest later year after 1970.
165166
* Include the current year, so subtract 2.
166167
*/
167-
year -= 2;
168+
PD_CHECK_OVERFLOW(checked_int64_sub(year, 2, &year));
168169
/* Subtract one day for each 4 years */
169-
days += year / 4;
170+
PD_CHECK_OVERFLOW(checked_int64_add(days, year / 4, &days));
170171
/* 2000 is the closest later year divisible by 100 */
171-
year -= 28;
172+
PD_CHECK_OVERFLOW(checked_int64_sub(year, 28, &year));
172173
/* Add one day for each 100 years */
173-
days -= year / 100;
174+
PD_CHECK_OVERFLOW(checked_int64_sub(days, year / 100, &days));
174175
/* 2000 is also the closest later year divisible by 400 */
175176
/* Subtract one day for each 400 years */
176-
days += year / 400;
177+
PD_CHECK_OVERFLOW(checked_int64_add(days, year / 400, &days));
177178
}
178179

179180
month_lengths = days_per_month_table[is_leapyear(dts->year)];
180181
month = dts->month - 1;
181182

182183
/* Add the months */
183184
for (i = 0; i < month; ++i) {
184-
days += month_lengths[i];
185+
PD_CHECK_OVERFLOW(checked_int64_add(days, month_lengths[i], &days));
185186
}
186187

187188
/* Add the days */
188-
days += dts->day - 1;
189+
PD_CHECK_OVERFLOW(checked_int64_add(days, dts->day - 1, &days));
189190

190191
return days;
191192
}
@@ -430,6 +431,15 @@ npy_datetime npy_datetimestruct_to_datetime(NPY_DATETIMEUNIT base,
430431
}
431432

432433
const int64_t days = get_datetimestruct_days(dts);
434+
if (days == -1) {
435+
PyGILState_STATE gstate = PyGILState_Ensure();
436+
bool did_error = PyErr_Occurred() == NULL ? false : true;
437+
PyGILState_Release(gstate);
438+
if (did_error) {
439+
return -1;
440+
}
441+
}
442+
433443
if (base == NPY_FR_D) {
434444
return days;
435445
}

0 commit comments

Comments
 (0)