From 6ff05a588dbca5583b046d09e268a83938720445 Mon Sep 17 00:00:00 2001 From: wjm <3201884732@qq.com> Date: Fri, 11 Oct 2024 14:51:27 +0800 Subject: [PATCH 1/4] DOC: Fix title capitalization in documentation file --- doc/source/whatsnew/v0.12.0.rst | 12 ++++++------ doc/source/whatsnew/v0.25.0.rst | 2 +- doc/source/whatsnew/v1.2.0.rst | 2 +- doc/source/whatsnew/v3.0.0.rst | 8 ++++---- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/doc/source/whatsnew/v0.12.0.rst b/doc/source/whatsnew/v0.12.0.rst index c805758f85b35..08d3a6b188322 100644 --- a/doc/source/whatsnew/v0.12.0.rst +++ b/doc/source/whatsnew/v0.12.0.rst @@ -133,9 +133,9 @@ API changes to be inserted if ``True``, default is ``False`` (same as prior to 0.12) (:issue:`3679`) - Implement ``__nonzero__`` for ``NDFrame`` objects (:issue:`3691`, :issue:`3696`) - - IO api + - IO API - - added top-level function ``read_excel`` to replace the following, + - Added top-level function ``read_excel`` to replace the following, The original API is deprecated and will be removed in a future version .. code-block:: python @@ -153,7 +153,7 @@ API changes pd.read_excel("path_to_file.xls", "Sheet1", index_col=None, na_values=["NA"]) - - added top-level function ``read_sql`` that is equivalent to the following + - Added top-level function ``read_sql`` that is equivalent to the following .. code-block:: python @@ -482,11 +482,11 @@ Bug fixes - ``HDFStore`` - - will retain index attributes (freq,tz,name) on recreation (:issue:`3499`) - - will warn with a ``AttributeConflictWarning`` if you are attempting to append + - Will retain index attributes (freq,tz,name) on recreation (:issue:`3499`) + - Will warn with a ``AttributeConflictWarning`` if you are attempting to append an index with a different frequency than the existing, or attempting to append an index with a different name than the existing - - support datelike columns with a timezone as data_columns (:issue:`2852`) + - Support datelike columns with a timezone as data_columns (:issue:`2852`) - Non-unique index support clarified (:issue:`3468`). diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index bddb47cd3f629..453fa38ef8fc3 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -551,7 +551,7 @@ with :attr:`numpy.nan` in the case of an empty :class:`DataFrame` (:issue:`26397 ``__str__`` methods now call ``__repr__`` rather than vice versa ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -pandas has until now mostly defined string representations in a pandas objects' +Pandas has until now mostly defined string representations in a pandas objects' ``__str__``/``__unicode__``/``__bytes__`` methods, and called ``__str__`` from the ``__repr__`` method, if a specific ``__repr__`` method is not found. This is not needed for Python3. In pandas 0.25, the string representations of pandas objects are now generally diff --git a/doc/source/whatsnew/v1.2.0.rst b/doc/source/whatsnew/v1.2.0.rst index 12ab4f27d1e62..fffcc39affccf 100644 --- a/doc/source/whatsnew/v1.2.0.rst +++ b/doc/source/whatsnew/v1.2.0.rst @@ -64,7 +64,7 @@ By default, duplicates continue to be allowed. label a [0, 1] -pandas will propagate the ``allows_duplicate_labels`` property through many operations. +Pandas will propagate the ``allows_duplicate_labels`` property through many operations. .. code-block:: ipython diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 321005272817d..2603238436665 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -16,12 +16,12 @@ Enhancements .. _whatsnew_300.enhancements.enhancement1: -enhancement1 +Enhancement1 ^^^^^^^^^^^^ .. _whatsnew_300.enhancements.enhancement2: -enhancement2 +Enhancement2 ^^^^^^^^^^^^ .. _whatsnew_300.enhancements.other: @@ -269,7 +269,7 @@ This change also applies to :meth:`.DataFrameGroupBy.value_counts`. Here, there Increased minimum version for Python ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -pandas 3.0.0 supports Python 3.10 and higher. +Pandas 3.0.0 supports Python 3.10 and higher. Increased minimum versions for dependencies ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -305,7 +305,7 @@ See :ref:`install.dependencies` and :ref:`install.optional_dependencies` for mor ``pytz`` now an optional dependency ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -pandas now uses :py:mod:`zoneinfo` from the standard library as the default timezone implementation when passing a timezone +Pandas now uses :py:mod:`zoneinfo` from the standard library as the default timezone implementation when passing a timezone string to various methods. (:issue:`34916`) *Old behavior:* From 5935a5380d62bcd63ec52196721ee542fc7c8c7b Mon Sep 17 00:00:00 2001 From: wjm <3201884732@qq.com> Date: Sat, 12 Oct 2024 08:16:03 +0800 Subject: [PATCH 2/4] DOC: Fix title capitalization in documentation files --- doc/source/whatsnew/v0.25.0.rst | 2 +- doc/source/whatsnew/v1.2.0.rst | 2 +- doc/source/whatsnew/v3.0.0.rst | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index 453fa38ef8fc3..bddb47cd3f629 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -551,7 +551,7 @@ with :attr:`numpy.nan` in the case of an empty :class:`DataFrame` (:issue:`26397 ``__str__`` methods now call ``__repr__`` rather than vice versa ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Pandas has until now mostly defined string representations in a pandas objects' +pandas has until now mostly defined string representations in a pandas objects' ``__str__``/``__unicode__``/``__bytes__`` methods, and called ``__str__`` from the ``__repr__`` method, if a specific ``__repr__`` method is not found. This is not needed for Python3. In pandas 0.25, the string representations of pandas objects are now generally diff --git a/doc/source/whatsnew/v1.2.0.rst b/doc/source/whatsnew/v1.2.0.rst index fffcc39affccf..12ab4f27d1e62 100644 --- a/doc/source/whatsnew/v1.2.0.rst +++ b/doc/source/whatsnew/v1.2.0.rst @@ -64,7 +64,7 @@ By default, duplicates continue to be allowed. label a [0, 1] -Pandas will propagate the ``allows_duplicate_labels`` property through many operations. +pandas will propagate the ``allows_duplicate_labels`` property through many operations. .. code-block:: ipython diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 2603238436665..e5376177d3381 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -269,7 +269,7 @@ This change also applies to :meth:`.DataFrameGroupBy.value_counts`. Here, there Increased minimum version for Python ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Pandas 3.0.0 supports Python 3.10 and higher. +pandas 3.0.0 supports Python 3.10 and higher. Increased minimum versions for dependencies ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -305,7 +305,7 @@ See :ref:`install.dependencies` and :ref:`install.optional_dependencies` for mor ``pytz`` now an optional dependency ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Pandas now uses :py:mod:`zoneinfo` from the standard library as the default timezone implementation when passing a timezone +pandas now uses :py:mod:`zoneinfo` from the standard library as the default timezone implementation when passing a timezone string to various methods. (:issue:`34916`) *Old behavior:* From d81e27842826cca6b9c96a852c6e5c6278af23a4 Mon Sep 17 00:00:00 2001 From: wjm <3201884732@qq.com> Date: Sun, 8 Dec 2024 19:28:45 +0800 Subject: [PATCH 3/4] Update variables a and b to names consistent with comment documentation --- pandas/core/computation/expressions.py | 70 +++++++++++++------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/pandas/core/computation/expressions.py b/pandas/core/computation/expressions.py index e2acd9a2c97c2..a2c3a706ae29c 100644 --- a/pandas/core/computation/expressions.py +++ b/pandas/core/computation/expressions.py @@ -65,23 +65,23 @@ def set_numexpr_threads(n=None) -> None: ne.set_num_threads(n) -def _evaluate_standard(op, op_str, a, b): +def _evaluate_standard(op, op_str, left_op, right_op): """ Standard evaluation. """ if _TEST_MODE: _store_test_result(False) - return op(a, b) + return op(left_op, right_op) -def _can_use_numexpr(op, op_str, a, b, dtype_check) -> bool: - """return a boolean if we WILL be using numexpr""" +def _can_use_numexpr(op, op_str, left_op, right_op, dtype_check) -> bool: + """return left_op boolean if we WILL be using numexpr""" if op_str is not None: # required min elements (otherwise we are adding overhead) - if a.size > _MIN_ELEMENTS: + if left_op.size > _MIN_ELEMENTS: # check for dtype compatibility dtypes: set[str] = set() - for o in [a, b]: + for o in [left_op, right_op]: # ndarray and Series Case if hasattr(o, "dtype"): dtypes |= {o.dtype.name} @@ -93,22 +93,22 @@ def _can_use_numexpr(op, op_str, a, b, dtype_check) -> bool: return False -def _evaluate_numexpr(op, op_str, a, b): +def _evaluate_numexpr(op, op_str, left_op, right_op): result = None - if _can_use_numexpr(op, op_str, a, b, "evaluate"): + if _can_use_numexpr(op, op_str, left_op, right_op, "evaluate"): is_reversed = op.__name__.strip("_").startswith("r") if is_reversed: # we were originally called by a reversed op method - a, b = b, a + left_op, right_op = right_op, left_op - a_value = a - b_value = b + left_value = left_op + right_value = right_op try: result = ne.evaluate( - f"a_value {op_str} b_value", - local_dict={"a_value": a_value, "b_value": b_value}, + f"left_value {op_str} right_value", + local_dict={"left_value": left_value, "right_value": right_op}, casting="safe", ) except TypeError: @@ -116,20 +116,20 @@ def _evaluate_numexpr(op, op_str, a, b): # (https://github.com/pydata/numexpr/issues/379) pass except NotImplementedError: - if _bool_arith_fallback(op_str, a, b): + if _bool_arith_fallback(op_str, left_op, right_op): pass else: raise if is_reversed: # reverse order to original for fallback - a, b = b, a + left_op, right_op = right_op, left_op if _TEST_MODE: _store_test_result(result is not None) if result is None: - result = _evaluate_standard(op, op_str, a, b) + result = _evaluate_standard(op, op_str, left_op, right_op) return result @@ -170,24 +170,24 @@ def _evaluate_numexpr(op, op_str, a, b): } -def _where_standard(cond, a, b): +def _where_standard(cond, left_op, right_op): # Caller is responsible for extracting ndarray if necessary - return np.where(cond, a, b) + return np.where(cond, left_op, right_op) -def _where_numexpr(cond, a, b): +def _where_numexpr(cond, left_op, right_op): # Caller is responsible for extracting ndarray if necessary result = None - if _can_use_numexpr(None, "where", a, b, "where"): + if _can_use_numexpr(None, "where", left_op, right_op, "where"): result = ne.evaluate( "where(cond_value, a_value, b_value)", - local_dict={"cond_value": cond, "a_value": a, "b_value": b}, + local_dict={"cond_value": cond, "a_value": left_op, "b_value": right_op}, casting="safe", ) if result is None: - result = _where_standard(cond, a, b) + result = _where_standard(cond, left_op, right_op) return result @@ -206,13 +206,13 @@ def _has_bool_dtype(x): _BOOL_OP_UNSUPPORTED = {"+": "|", "*": "&", "-": "^"} -def _bool_arith_fallback(op_str, a, b) -> bool: +def _bool_arith_fallback(op_str, left_op, right_op) -> bool: """ Check if we should fallback to the python `_evaluate_standard` in case of an unsupported operation by numexpr, which is the case for some boolean ops. """ - if _has_bool_dtype(a) and _has_bool_dtype(b): + if _has_bool_dtype(left_op) and _has_bool_dtype(right_op): if op_str in _BOOL_OP_UNSUPPORTED: warnings.warn( f"evaluating in Python space because the {op_str!r} " @@ -224,15 +224,15 @@ def _bool_arith_fallback(op_str, a, b) -> bool: return False -def evaluate(op, a, b, use_numexpr: bool = True): +def evaluate(op, left_op, right_op, use_numexpr: bool = True): """ - Evaluate and return the expression of the op on a and b. + Evaluate and return the expression of the op on left_op and right_op. Parameters ---------- op : the actual operand - a : left operand - b : right operand + left_op : left operand + right_op : right operand use_numexpr : bool, default True Whether to try to use numexpr. """ @@ -240,24 +240,24 @@ def evaluate(op, a, b, use_numexpr: bool = True): if op_str is not None: if use_numexpr: # error: "None" not callable - return _evaluate(op, op_str, a, b) # type: ignore[misc] - return _evaluate_standard(op, op_str, a, b) + return _evaluate(op, op_str, left_op, right_op) # type: ignore[misc] + return _evaluate_standard(op, op_str, left_op, right_op) -def where(cond, a, b, use_numexpr: bool = True): +def where(cond, left_op, right_op, use_numexpr: bool = True): """ - Evaluate the where condition cond on a and b. + Evaluate the where condition cond on left_op and right_op. Parameters ---------- cond : np.ndarray[bool] - a : return if cond is True - b : return if cond is False + left_op : return if cond is True + right_op : return if cond is False use_numexpr : bool, default True Whether to try to use numexpr. """ assert _where is not None - return _where(cond, a, b) if use_numexpr else _where_standard(cond, a, b) + return _where(cond, left_op, right_op) if use_numexpr else _where_standard(cond, left_op, right_op) def set_test_mode(v: bool = True) -> None: From 45d6b2f26965182d28e04d30081d1f8d201ff78e Mon Sep 17 00:00:00 2001 From: wjm <3201884732@qq.com> Date: Tue, 10 Dec 2024 10:39:15 +0800 Subject: [PATCH 4/4] DOC: Fix DataFrame.size docstring --- pandas/core/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index d1aa20501b060..de7fb3682fb4f 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -665,7 +665,7 @@ def size(self) -> int: See Also -------- - ndarray.size : Number of elements in the array. + numpy.ndarray.size : Number of elements in the array. Examples --------