diff --git a/ci/code_checks.sh b/ci/code_checks.sh index b40ef36723b46..0c38cbb2fc767 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -65,8 +65,8 @@ fi ### DOCSTRINGS ### if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then - MSG='Validate docstrings (EX01, EX02, EX04, GL01, GL02, GL03, GL04, GL05, GL06, GL07, GL09, GL10, PR03, PR04, PR05, PR06, PR08, PR09, PR10, RT01, RT02, RT04, RT05, SA02, SA03, SA04, SS01, SS02, SS03, SS04, SS05, SS06)' ; echo $MSG - $BASE_DIR/scripts/validate_docstrings.py --format=actions --errors=EX01,EX02,EX04,GL01,GL02,GL03,GL04,GL05,GL06,GL07,GL09,GL10,PR03,PR04,PR05,PR06,PR08,PR09,PR10,RT01,RT02,RT04,RT05,SA02,SA03,SA04,SS01,SS02,SS03,SS04,SS05,SS06 + MSG='Validate docstrings (EX01, EX04, GL01, GL02, GL03, GL04, GL05, GL06, GL07, GL09, GL10, PR03, PR04, PR05, PR06, PR08, PR09, PR10, RT01, RT02, RT04, RT05, SA02, SA03, SA04, SS01, SS02, SS03, SS04, SS05, SS06)' ; echo $MSG + $BASE_DIR/scripts/validate_docstrings.py --format=actions --errors=EX01,EX04,GL01,GL02,GL03,GL04,GL05,GL06,GL07,GL09,GL10,PR03,PR04,PR05,PR06,PR08,PR09,PR10,RT01,RT02,RT04,RT05,SA02,SA03,SA04,SS01,SS02,SS03,SS04,SS05,SS06 RET=$(($RET + $?)) ; echo $MSG "DONE" fi diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 56efc5aea6081..8e7f40a01b809 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -3554,7 +3554,7 @@ def to_latex( >>> print(df.to_latex(index=False, ... formatters={"name": str.upper}, ... float_format="{:.1f}".format, - ... )) # doctest: +SKIP + ... )) # doctest: +SKIP \begin{tabular}{lrr} \toprule name & age & height \\ diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 4ef61fa08b792..7bbc7894a1050 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -444,14 +444,15 @@ class providing the base-class of operations. a `(callable, data_keyword)` tuple where `data_keyword` is a string indicating the keyword of `callable` that expects the %(klass)s object. -args : iterable, optional +*args : iterable, optional Positional arguments passed into `func`. -kwargs : dict, optional +**kwargs : dict, optional A dictionary of keyword arguments passed into `func`. Returns ------- -the return type of `func`. +%(klass)s + The original object with the function `func` applied. See Also -------- diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index 966c4646ac773..c9cbd1a6b83fd 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -785,7 +785,7 @@ def to_latex( For example the following code will highlight and bold a cell in HTML-CSS: - >>> df = pd.DataFrame([[1,2], [3,4]]) + >>> df = pd.DataFrame([[1, 2], [3, 4]]) >>> s = df.style.highlight_max(axis=None, ... props='background-color:red; font-weight:bold;') >>> s.to_html() # doctest: +SKIP @@ -908,9 +908,9 @@ def to_latex( >>> s.table_styles = [] >>> s.caption = None >>> s.format({ - ... ("Numeric", "Integers"): '\${}', - ... ("Numeric", "Floats"): '{:.3f}', - ... ("Non-Numeric", "Strings"): str.upper + ... ("Numeric", "Integers"): '\\${}', + ... ("Numeric", "Floats"): '{:.3f}', + ... ("Non-Numeric", "Strings"): str.upper ... }) # doctest: +SKIP Numeric Non-Numeric Integers Floats Strings diff --git a/pandas/io/pickle.py b/pandas/io/pickle.py index 0ed146f03dedc..d3e93ebeb8fbb 100644 --- a/pandas/io/pickle.py +++ b/pandas/io/pickle.py @@ -123,7 +123,7 @@ def read_pickle( storage_options: StorageOptions | None = None, ) -> DataFrame | Series: """ - Load pickled pandas object (or any object) from file. + Load pickled pandas object (or any object) from file and return unpickled object. .. warning:: @@ -145,7 +145,8 @@ def read_pickle( Returns ------- - same type as object stored in file + object + The unpickled pandas object (or any object) that was stored in file. See Also -------- diff --git a/pandas/tests/io/test_sql.py b/pandas/tests/io/test_sql.py index 2ddbbaa1bf17c..d86b80691190d 100644 --- a/pandas/tests/io/test_sql.py +++ b/pandas/tests/io/test_sql.py @@ -2229,12 +2229,14 @@ def test_api_chunksize_read(conn, request): @pytest.mark.parametrize("conn", all_connectable) def test_api_categorical(conn, request): if conn == "postgresql_adbc_conn": - request.node.add_marker( - pytest.mark.xfail( - reason="categorical dtype not implemented for ADBC postgres driver", - strict=True, + adbc = import_optional_dependency("adbc_driver_postgresql", errors="ignore") + if adbc is not None and Version(adbc.__version__) < Version("0.9.0"): + request.node.add_marker( + pytest.mark.xfail( + reason="categorical dtype not implemented for ADBC postgres driver", + strict=True, + ) ) - ) # GH8624 # test that categorical gets written correctly as dense column conn = request.getfixturevalue(conn) diff --git a/scripts/tests/test_validate_docstrings.py b/scripts/tests/test_validate_docstrings.py index 4e935b3d6e451..77f667dc61ab6 100644 --- a/scripts/tests/test_validate_docstrings.py +++ b/scripts/tests/test_validate_docstrings.py @@ -136,12 +136,6 @@ def test_bad_docstrings(self, capsys, klass, func, msgs) -> None: for msg in msgs: assert msg in " ".join([err[1] for err in result["errors"]]) - def test_leftover_files_raises(self) -> None: - with pytest.raises(Exception, match="The following files"): - validate_docstrings.pandas_validate( - self._import_path(klass="BadDocstrings", func="leftover_files") - ) - def test_validate_all_ignore_functions(self, monkeypatch) -> None: monkeypatch.setattr( validate_docstrings, diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index 45e0f849fc508..555f68fa16c23 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -18,23 +18,18 @@ import argparse import doctest import importlib -import io import json -import os import pathlib import sys import matplotlib import matplotlib.pyplot as plt -import numpy from numpydoc.docscrape import get_doc_object from numpydoc.validate import ( Validator, validate, ) -import pandas - # With template backend, matplotlib plots nothing matplotlib.use("template") @@ -61,7 +56,6 @@ "GL05": "Use 'array-like' rather than 'array_like' in docstrings.", "SA05": "{reference_name} in `See Also` section does not need `pandas` " "prefix, use {right_reference} instead.", - "EX02": "Examples do not pass tests:\n{doctest_log}", "EX04": "Do not import {imported_library}, as it is imported " "automatically for the examples (numpy as np, pandas as pd)", } @@ -163,32 +157,6 @@ def name(self): def mentioned_private_classes(self): return [klass for klass in PRIVATE_CLASSES if klass in self.raw_doc] - @property - def examples_errors(self): - flags = doctest.NORMALIZE_WHITESPACE | doctest.IGNORE_EXCEPTION_DETAIL - finder = doctest.DocTestFinder() - runner = doctest.DocTestRunner(optionflags=flags) - context = {"np": numpy, "pd": pandas} - error_msgs = "" - current_dir = set(os.listdir()) - for test in finder.find(self.raw_doc, self.name, globs=context): - f = io.StringIO() - runner.run(test, out=f.write) - error_msgs += f.getvalue() - leftovers = set(os.listdir()).difference(current_dir) - if leftovers: - for leftover in leftovers: - path = pathlib.Path(leftover).resolve() - if path.is_dir(): - path.rmdir() - elif path.is_file(): - path.unlink(missing_ok=True) - raise Exception( - f"The following files were leftover from the doctest: " - f"{leftovers}. Please use # doctest: +SKIP" - ) - return error_msgs - @property def examples_source_code(self): lines = doctest.DocTestParser().get_examples(self.raw_doc) @@ -237,12 +205,6 @@ def pandas_validate(func_name: str): result["examples_errs"] = "" if doc.examples: - result["examples_errs"] = doc.examples_errors - if result["examples_errs"]: - result["errors"].append( - pandas_error("EX02", doctest_log=result["examples_errs"]) - ) - examples_source_code = "".join(doc.examples_source_code) result["errors"].extend( pandas_error("EX04", imported_library=wrong_import) @@ -366,9 +328,6 @@ def header(title, width=80, char="#") -> str: if result["errors"]: sys.stderr.write(f'{len(result["errors"])} Errors found for `{func_name}`:\n') for err_code, err_desc in result["errors"]: - if err_code == "EX02": # Failing examples are printed at the end - sys.stderr.write("\tExamples do not pass tests\n") - continue sys.stderr.write(f"\t{err_desc}\n") else: sys.stderr.write(f'Docstring for "{func_name}" correct. :)\n')