Skip to content

Commit 4a3e0de

Browse files
authored
Merge branch 'main' into cln-enforce-deprec-H-BH-CBH
2 parents 4085d5c + dcb5494 commit 4a3e0de

File tree

27 files changed

+242
-244
lines changed

27 files changed

+242
-244
lines changed

.pre-commit-config.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ ci:
1919
skip: [pyright, mypy]
2020
repos:
2121
- repo: https://github.com/astral-sh/ruff-pre-commit
22-
rev: v0.4.7
22+
rev: v0.5.0
2323
hooks:
2424
- id: ruff
2525
args: [--exit-non-zero-on-fix]
@@ -73,7 +73,7 @@ repos:
7373
hooks:
7474
- id: isort
7575
- repo: https://github.com/asottile/pyupgrade
76-
rev: v3.15.2
76+
rev: v3.16.0
7777
hooks:
7878
- id: pyupgrade
7979
args: [--py310-plus]
@@ -93,7 +93,7 @@ repos:
9393
- id: sphinx-lint
9494
args: ["--enable", "all", "--disable", "line-too-long"]
9595
- repo: https://github.com/pre-commit/mirrors-clang-format
96-
rev: v18.1.5
96+
rev: v18.1.8
9797
hooks:
9898
- id: clang-format
9999
files: ^pandas/_libs/src|^pandas/_libs/include

ci/code_checks.sh

-2
Original file line numberDiff line numberDiff line change
@@ -244,13 +244,11 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
244244
-i "pandas.Timestamp.month_name SA01" \
245245
-i "pandas.Timestamp.nanosecond GL08" \
246246
-i "pandas.Timestamp.normalize SA01" \
247-
-i "pandas.Timestamp.now SA01" \
248247
-i "pandas.Timestamp.quarter SA01" \
249248
-i "pandas.Timestamp.replace PR07,SA01" \
250249
-i "pandas.Timestamp.resolution PR02" \
251250
-i "pandas.Timestamp.second GL08" \
252251
-i "pandas.Timestamp.strptime PR01,SA01" \
253-
-i "pandas.Timestamp.time SA01" \
254252
-i "pandas.Timestamp.timestamp SA01" \
255253
-i "pandas.Timestamp.timetuple SA01" \
256254
-i "pandas.Timestamp.timetz SA01" \

doc/source/whatsnew/v3.0.0.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -565,8 +565,8 @@ I/O
565565
- Bug in :meth:`read_csv` raising ``TypeError`` when ``index_col`` is specified and ``na_values`` is a dict containing the key ``None``. (:issue:`57547`)
566566
- Bug in :meth:`read_csv` raising ``TypeError`` when ``nrows`` and ``iterator`` are specified without specifying a ``chunksize``. (:issue:`59079`)
567567
- Bug in :meth:`read_excel` raising ``ValueError`` when passing array of boolean values when ``dtype="boolean"``. (:issue:`58159`)
568+
- Bug in :meth:`read_json` not validating the ``typ`` argument to not be exactly ``"frame"`` or ``"series"`` (:issue:`59124`)
568569
- Bug in :meth:`read_stata` raising ``KeyError`` when input file is stored in big-endian format and contains strL data. (:issue:`58638`)
569-
-
570570

571571
Period
572572
^^^^^^
@@ -598,6 +598,7 @@ Reshaping
598598
^^^^^^^^^
599599
- Bug in :meth:`DataFrame.join` inconsistently setting result index name (:issue:`55815`)
600600
- Bug in :meth:`DataFrame.unstack` producing incorrect results when ``sort=False`` (:issue:`54987`, :issue:`55516`)
601+
- Bug in :meth:`DataFrame.unstack` producing incorrect results when manipulating empty :class:`DataFrame` with an :class:`ExtentionDtype` (:issue:`59123`)
601602

602603
Sparse
603604
^^^^^^
@@ -617,6 +618,7 @@ Other
617618
^^^^^
618619
- Bug in :class:`DataFrame` when passing a ``dict`` with a NA scalar and ``columns`` that would always return ``np.nan`` (:issue:`57205`)
619620
- Bug in :func:`eval` on :class:`ExtensionArray` on including division ``/`` failed with a ``TypeError``. (:issue:`58748`)
621+
- Bug in :func:`eval` on :class:`complex` including division ``/`` discards imaginary part. (:issue:`21374`)
620622
- Bug in :func:`eval` where the names of the :class:`Series` were not preserved when using ``engine="numexpr"``. (:issue:`10239`)
621623
- Bug in :func:`unique` on :class:`Index` not always returning :class:`Index` (:issue:`57043`)
622624
- Bug in :meth:`DataFrame.apply` where passing ``engine="numba"`` ignored ``args`` passed to the applied function (:issue:`58712`)

pandas/_libs/src/datetime/pd_datetime.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,12 @@ static int pandas_datetime_exec(PyObject *Py_UNUSED(module)) {
245245
}
246246

247247
static PyModuleDef_Slot pandas_datetime_slots[] = {
248-
{Py_mod_exec, pandas_datetime_exec}, {0, NULL}};
248+
{Py_mod_exec, pandas_datetime_exec},
249+
#if PY_VERSION_HEX >= 0x030D0000
250+
{Py_mod_gil, Py_MOD_GIL_NOT_USED},
251+
#endif
252+
{0, NULL},
253+
};
249254

250255
static struct PyModuleDef pandas_datetimemodule = {
251256
PyModuleDef_HEAD_INIT,

pandas/_libs/src/parser/pd_parser.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,12 @@ static int pandas_parser_exec(PyObject *Py_UNUSED(module)) {
161161
}
162162

163163
static PyModuleDef_Slot pandas_parser_slots[] = {
164-
{Py_mod_exec, pandas_parser_exec}, {0, NULL}};
164+
{Py_mod_exec, pandas_parser_exec},
165+
#if PY_VERSION_HEX >= 0x030D0000
166+
{Py_mod_gil, Py_MOD_GIL_NOT_USED},
167+
#endif
168+
{0, NULL},
169+
};
165170

166171
static struct PyModuleDef pandas_parsermodule = {
167172
PyModuleDef_HEAD_INIT,

pandas/_libs/tslibs/nattype.pyx

+20
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,16 @@ class NaTType(_NaT):
633633
"""
634634
Return time object with same time but with tzinfo=None.
635635
636+
This method extracts the time part of the `Timestamp` object, excluding any
637+
timezone information. It returns a `datetime.time` object which only represents
638+
the time (hours, minutes, seconds, and microseconds).
639+
640+
See Also
641+
--------
642+
Timestamp.date : Return date object with same year, month and day.
643+
Timestamp.tz_convert : Convert timezone-aware Timestamp to another time zone.
644+
Timestamp.tz_localize : Localize the Timestamp to a timezone.
645+
636646
Examples
637647
--------
638648
>>> ts = pd.Timestamp('2023-01-01 10:00:00')
@@ -957,11 +967,21 @@ class NaTType(_NaT):
957967
"""
958968
Return new Timestamp object representing current time local to tz.
959969
970+
This method returns a new `Timestamp` object that represents the current time.
971+
If a timezone is provided, the current time will be localized to that timezone.
972+
Otherwise, it returns the current local time.
973+
960974
Parameters
961975
----------
962976
tz : str or timezone object, default None
963977
Timezone to localize to.
964978
979+
See Also
980+
--------
981+
to_datetime : Convert argument to datetime.
982+
Timestamp.utcnow : Return a new Timestamp representing UTC day and time.
983+
Timestamp.today : Return the current time in the local timezone.
984+
965985
Examples
966986
--------
967987
>>> pd.Timestamp.now() # doctest: +SKIP

pandas/_libs/tslibs/timestamps.pyx

+20
Original file line numberDiff line numberDiff line change
@@ -1465,11 +1465,21 @@ class Timestamp(_Timestamp):
14651465
"""
14661466
Return new Timestamp object representing current time local to tz.
14671467
1468+
This method returns a new `Timestamp` object that represents the current time.
1469+
If a timezone is provided, the current time will be localized to that timezone.
1470+
Otherwise, it returns the current local time.
1471+
14681472
Parameters
14691473
----------
14701474
tz : str or timezone object, default None
14711475
Timezone to localize to.
14721476
1477+
See Also
1478+
--------
1479+
to_datetime : Convert argument to datetime.
1480+
Timestamp.utcnow : Return a new Timestamp representing UTC day and time.
1481+
Timestamp.today : Return the current time in the local timezone.
1482+
14731483
Examples
14741484
--------
14751485
>>> pd.Timestamp.now() # doctest: +SKIP
@@ -1768,6 +1778,16 @@ class Timestamp(_Timestamp):
17681778
"""
17691779
Return time object with same time but with tzinfo=None.
17701780
1781+
This method extracts the time part of the `Timestamp` object, excluding any
1782+
timezone information. It returns a `datetime.time` object which only represents
1783+
the time (hours, minutes, seconds, and microseconds).
1784+
1785+
See Also
1786+
--------
1787+
Timestamp.date : Return date object with same year, month and day.
1788+
Timestamp.tz_convert : Convert timezone-aware Timestamp to another time zone.
1789+
Timestamp.tz_localize : Localize the Timestamp to a timezone.
1790+
17711791
Examples
17721792
--------
17731793
>>> ts = pd.Timestamp('2023-01-01 10:00:00')

pandas/_testing/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107

108108
COMPLEX_DTYPES: list[Dtype] = [complex, "complex64", "complex128"]
109109
STRING_DTYPES: list[Dtype] = [str, "str", "U"]
110+
COMPLEX_FLOAT_DTYPES: list[Dtype] = [*COMPLEX_DTYPES, *FLOAT_NUMPY_DTYPES]
110111

111112
DATETIME64_DTYPES: list[Dtype] = ["datetime64[ns]", "M8[ns]"]
112113
TIMEDELTA64_DTYPES: list[Dtype] = ["timedelta64[ns]", "m8[ns]"]

pandas/conftest.py

+15
Original file line numberDiff line numberDiff line change
@@ -1448,6 +1448,21 @@ def complex_dtype(request):
14481448
return request.param
14491449

14501450

1451+
@pytest.fixture(params=tm.COMPLEX_FLOAT_DTYPES)
1452+
def complex_or_float_dtype(request):
1453+
"""
1454+
Parameterized fixture for complex and numpy float dtypes.
1455+
1456+
* complex
1457+
* 'complex64'
1458+
* 'complex128'
1459+
* float
1460+
* 'float32'
1461+
* 'float64'
1462+
"""
1463+
return request.param
1464+
1465+
14511466
@pytest.fixture(params=tm.SIGNED_INT_NUMPY_DTYPES)
14521467
def any_signed_int_numpy_dtype(request):
14531468
"""

pandas/core/common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def is_bool_indexer(key: Any) -> bool:
145145
elif isinstance(key, list):
146146
# check if np.array(key).dtype would be bool
147147
if len(key) > 0:
148-
if type(key) is not list: # noqa: E721
148+
if type(key) is not list:
149149
# GH#42461 cython will raise TypeError if we pass a subclass
150150
key = list(key)
151151
return lib.is_bool_list(key)

pandas/core/computation/expr.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
UNARY_OPS_SYMS,
3333
BinOp,
3434
Constant,
35-
Div,
3635
FuncNode,
3736
Op,
3837
Term,
@@ -374,7 +373,7 @@ class BaseExprVisitor(ast.NodeVisitor):
374373
"Add",
375374
"Sub",
376375
"Mult",
377-
None,
376+
"Div",
378377
"Pow",
379378
"FloorDiv",
380379
"Mod",
@@ -537,9 +536,6 @@ def visit_BinOp(self, node, **kwargs):
537536
left, right = self._maybe_downcast_constants(left, right)
538537
return self._maybe_evaluate_binop(op, op_class, left, right)
539538

540-
def visit_Div(self, node, **kwargs):
541-
return lambda lhs, rhs: Div(lhs, rhs)
542-
543539
def visit_UnaryOp(self, node, **kwargs):
544540
op = self.visit(node.op)
545541
operand = self.visit(node.operand)

pandas/core/computation/ops.py

-52
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
from pandas.core.dtypes.common import (
2020
is_list_like,
21-
is_numeric_dtype,
2221
is_scalar,
2322
)
2423

@@ -328,31 +327,6 @@ def _not_in(x, y):
328327
_binary_ops_dict.update(d)
329328

330329

331-
def _cast_inplace(terms, acceptable_dtypes, dtype) -> None:
332-
"""
333-
Cast an expression inplace.
334-
335-
Parameters
336-
----------
337-
terms : Op
338-
The expression that should cast.
339-
acceptable_dtypes : list of acceptable numpy.dtype
340-
Will not cast if term's dtype in this list.
341-
dtype : str or numpy.dtype
342-
The dtype to cast to.
343-
"""
344-
dt = np.dtype(dtype)
345-
for term in terms:
346-
if term.type in acceptable_dtypes:
347-
continue
348-
349-
try:
350-
new_value = term.value.astype(dt)
351-
except AttributeError:
352-
new_value = dt.type(term.value)
353-
term.update(new_value)
354-
355-
356330
def is_term(obj) -> bool:
357331
return isinstance(obj, Term)
358332

@@ -509,32 +483,6 @@ def _disallow_scalar_only_bool_ops(self) -> None:
509483
raise NotImplementedError("cannot evaluate scalar only bool ops")
510484

511485

512-
class Div(BinOp):
513-
"""
514-
Div operator to special case casting.
515-
516-
Parameters
517-
----------
518-
lhs, rhs : Term or Op
519-
The Terms or Ops in the ``/`` expression.
520-
"""
521-
522-
def __init__(self, lhs, rhs) -> None:
523-
super().__init__("/", lhs, rhs)
524-
525-
if not is_numeric_dtype(lhs.return_type) or not is_numeric_dtype(
526-
rhs.return_type
527-
):
528-
raise TypeError(
529-
f"unsupported operand type(s) for {self.op}: "
530-
f"'{lhs.return_type}' and '{rhs.return_type}'"
531-
)
532-
533-
# do not upcast float32s to float64 un-necessarily
534-
acceptable_dtypes = [np.float32, np.float64]
535-
_cast_inplace(com.flatten(self), acceptable_dtypes, np.float64)
536-
537-
538486
UNARY_OPS_SYMS = ("+", "-", "~", "not")
539487
_unary_ops_funcs = (operator.pos, operator.neg, operator.invert, operator.invert)
540488
_unary_ops_dict = dict(zip(UNARY_OPS_SYMS, _unary_ops_funcs))

pandas/core/indexes/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7528,7 +7528,7 @@ def ensure_index(index_like: Axes, copy: bool = False) -> Index:
75287528
index_like = list(index_like)
75297529

75307530
if isinstance(index_like, list):
7531-
if type(index_like) is not list: # noqa: E721
7531+
if type(index_like) is not list:
75327532
# must check for exactly list here because of strict type
75337533
# check in clean_index_list
75347534
index_like = list(index_like)

pandas/core/internals/construction.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ def _list_of_dict_to_arrays(
842842

843843
# assure that they are of the base dict class and not of derived
844844
# classes
845-
data = [d if type(d) is dict else dict(d) for d in data] # noqa: E721
845+
data = [d if type(d) is dict else dict(d) for d in data]
846846

847847
content = lib.dicts_to_array(data, list(columns))
848848
return content, columns

pandas/core/reshape/reshape.py

+11-13
Original file line numberDiff line numberDiff line change
@@ -288,21 +288,19 @@ def get_new_values(self, values, fill_value=None):
288288

289289
dtype = values.dtype
290290

291-
# if our mask is all True, then we can use our existing dtype
292-
if mask_all:
293-
dtype = values.dtype
294-
new_values = np.empty(result_shape, dtype=dtype)
295-
else:
296-
if isinstance(dtype, ExtensionDtype):
297-
# GH#41875
298-
# We are assuming that fill_value can be held by this dtype,
299-
# unlike the non-EA case that promotes.
300-
cls = dtype.construct_array_type()
301-
new_values = cls._empty(result_shape, dtype=dtype)
291+
if isinstance(dtype, ExtensionDtype):
292+
# GH#41875
293+
# We are assuming that fill_value can be held by this dtype,
294+
# unlike the non-EA case that promotes.
295+
cls = dtype.construct_array_type()
296+
new_values = cls._empty(result_shape, dtype=dtype)
297+
if not mask_all:
302298
new_values[:] = fill_value
303-
else:
299+
else:
300+
if not mask_all:
304301
dtype, fill_value = maybe_promote(dtype, fill_value)
305-
new_values = np.empty(result_shape, dtype=dtype)
302+
new_values = np.empty(result_shape, dtype=dtype)
303+
if not mask_all:
306304
new_values.fill(fill_value)
307305

308306
name = dtype.name

pandas/core/series.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -6567,7 +6567,7 @@ def min(
65676567
Returns
65686568
-------
65696569
scalar or Series (if level specified)
6570-
The maximum of the values in the Series.
6570+
The minimum of the values in the Series.
65716571
65726572
See Also
65736573
--------
@@ -6716,7 +6716,7 @@ def sum(
67166716
Returns
67176717
-------
67186718
scalar or Series (if level specified)
6719-
Median of the values for the requested axis.
6719+
Sum of the values for the requested axis.
67206720
67216721
See Also
67226722
--------
@@ -6826,7 +6826,7 @@ def mean(
68266826
Returns
68276827
-------
68286828
scalar or Series (if level specified)
6829-
Median of the values for the requested axis.
6829+
Mean of the values for the requested axis.
68306830
68316831
See Also
68326832
--------

pandas/core/tools/datetimes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class FulldatetimeDict(YearMonthDayDict, total=False):
129129
def _guess_datetime_format_for_array(arr, dayfirst: bool | None = False) -> str | None:
130130
# Try to guess the format based on the first non-NaN element, return None if can't
131131
if (first_non_null := tslib.first_non_null(arr)) != -1:
132-
if type(first_non_nan_element := arr[first_non_null]) is str: # noqa: E721
132+
if type(first_non_nan_element := arr[first_non_null]) is str:
133133
# GH#32264 np.str_ object
134134
guessed_format = guess_datetime_format(
135135
first_non_nan_element, dayfirst=dayfirst

0 commit comments

Comments
 (0)