Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into sty/ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
mroeschke committed Jan 14, 2024
2 parents 6386676 + 73bc5f4 commit 78aa82d
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 64 deletions.
4 changes: 2 additions & 2 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 \\
Expand Down
7 changes: 4 additions & 3 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------
Expand Down
8 changes: 4 additions & 4 deletions pandas/io/formats/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions pandas/io/pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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::
Expand All @@ -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
--------
Expand Down
12 changes: 7 additions & 5 deletions pandas/tests/io/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 0 additions & 6 deletions scripts/tests/test_validate_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
41 changes: 0 additions & 41 deletions scripts/validate_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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)",
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit 78aa82d

Please sign in to comment.