Skip to content

Commit 461ebf0

Browse files
committed
merged main
2 parents 75e342a + 69fe98d commit 461ebf0

File tree

21 files changed

+174
-223
lines changed

21 files changed

+174
-223
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,6 @@ 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" \

doc/source/whatsnew/v3.0.0.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,7 @@ I/O
564564
- Bug in :meth:`read_csv` raising ``TypeError`` when ``nrows`` and ``iterator`` are specified without specifying a ``chunksize``. (:issue:`59079`)
565565
- Bug in :meth:`read_excel` raising ``ValueError`` when passing array of boolean values when ``dtype="boolean"``. (:issue:`58159`)
566566
- Bug in :meth:`read_html` would return an incorrect result when parsing a table with a space character in a ``<td>`` tag. (:issue:`12345`)
567+
- Bug in :meth:`read_json` not validating the ``typ`` argument to not be exactly ``"frame"`` or ``"series"`` (:issue:`59124`)
567568
- Bug in :meth:`read_stata` raising ``KeyError`` when input file is stored in big-endian format and contains strL data. (:issue:`58638`)
568569

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

pandas/_libs/tslibs/nattype.pyx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,11 +957,21 @@ class NaTType(_NaT):
957957
"""
958958
Return new Timestamp object representing current time local to tz.
959959
960+
This method returns a new `Timestamp` object that represents the current time.
961+
If a timezone is provided, the current time will be localized to that timezone.
962+
Otherwise, it returns the current local time.
963+
960964
Parameters
961965
----------
962966
tz : str or timezone object, default None
963967
Timezone to localize to.
964968
969+
See Also
970+
--------
971+
to_datetime : Convert argument to datetime.
972+
Timestamp.utcnow : Return a new Timestamp representing UTC day and time.
973+
Timestamp.today : Return the current time in the local timezone.
974+
965975
Examples
966976
--------
967977
>>> pd.Timestamp.now() # doctest: +SKIP

pandas/_libs/tslibs/timestamps.pyx

Lines changed: 10 additions & 0 deletions
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

pandas/_testing/__init__.py

Lines changed: 1 addition & 0 deletions
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

Lines changed: 15 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 5 deletions
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

Lines changed: 0 additions & 52 deletions
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))

0 commit comments

Comments
 (0)