Skip to content

Commit a1b759c

Browse files
authored
Merge branch 'main' into CI-Improve-error-messge
2 parents 7ef9b5d + 73bc5f4 commit a1b759c

File tree

8 files changed

+22
-65
lines changed

8 files changed

+22
-65
lines changed

ci/code_checks.sh

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,14 @@ fi
6565
### DOCSTRINGS ###
6666
if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
6767

68-
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
69-
$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
68+
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
69+
$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
7070
RET=$(($RET + $?)) ; echo $MSG "DONE"
7171

7272
MSG='Partially validate docstrings (EX03)' ; echo $MSG
7373
$BASE_DIR/scripts/validate_docstrings.py --format=actions --errors=EX03 --ignore_functions \
7474
pandas.Series.plot.line \
7575
pandas.Series.to_sql \
76-
pandas.Series.to_latex \
7776
pandas.errors.DatabaseError \
7877
pandas.errors.IndexingError \
7978
pandas.errors.InvalidColumnName \
@@ -87,16 +86,13 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
8786
pandas.Timestamp.ceil \
8887
pandas.Timestamp.floor \
8988
pandas.Timestamp.round \
90-
pandas.read_pickle \
9189
pandas.ExcelWriter \
9290
pandas.read_json \
9391
pandas.io.json.build_table_schema \
94-
pandas.DataFrame.to_latex \
9592
pandas.io.formats.style.Styler.to_latex \
9693
pandas.read_parquet \
9794
pandas.DataFrame.to_sql \
9895
pandas.read_stata \
99-
pandas.core.resample.Resampler.pipe \
10096
pandas.core.resample.Resampler.interpolate \
10197
pandas.plotting.scatter_matrix \
10298
pandas.pivot \

pandas/core/generic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3544,7 +3544,7 @@ def to_latex(
35443544
>>> print(df.to_latex(index=False,
35453545
... formatters={"name": str.upper},
35463546
... float_format="{:.1f}".format,
3547-
... )) # doctest: +SKIP
3547+
... )) # doctest: +SKIP
35483548
\begin{tabular}{lrr}
35493549
\toprule
35503550
name & age & height \\

pandas/core/groupby/groupby.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -444,14 +444,15 @@ class providing the base-class of operations.
444444
a `(callable, data_keyword)` tuple where `data_keyword` is a
445445
string indicating the keyword of `callable` that expects the
446446
%(klass)s object.
447-
args : iterable, optional
447+
*args : iterable, optional
448448
Positional arguments passed into `func`.
449-
kwargs : dict, optional
449+
**kwargs : dict, optional
450450
A dictionary of keyword arguments passed into `func`.
451451
452452
Returns
453453
-------
454-
the return type of `func`.
454+
%(klass)s
455+
The original object with the function `func` applied.
455456
456457
See Also
457458
--------

pandas/io/formats/style.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ def to_latex(
770770
771771
For example the following code will highlight and bold a cell in HTML-CSS:
772772
773-
>>> df = pd.DataFrame([[1,2], [3,4]])
773+
>>> df = pd.DataFrame([[1, 2], [3, 4]])
774774
>>> s = df.style.highlight_max(axis=None,
775775
... props='background-color:red; font-weight:bold;')
776776
>>> s.to_html() # doctest: +SKIP
@@ -893,9 +893,9 @@ def to_latex(
893893
>>> s.table_styles = []
894894
>>> s.caption = None
895895
>>> s.format({
896-
... ("Numeric", "Integers"): '\${}',
897-
... ("Numeric", "Floats"): '{:.3f}',
898-
... ("Non-Numeric", "Strings"): str.upper
896+
... ("Numeric", "Integers"): '\\${}',
897+
... ("Numeric", "Floats"): '{:.3f}',
898+
... ("Non-Numeric", "Strings"): str.upper
899899
... }) # doctest: +SKIP
900900
Numeric Non-Numeric
901901
Integers Floats Strings

pandas/io/pickle.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def read_pickle(
121121
storage_options: StorageOptions | None = None,
122122
) -> DataFrame | Series:
123123
"""
124-
Load pickled pandas object (or any object) from file.
124+
Load pickled pandas object (or any object) from file and return unpickled object.
125125
126126
.. warning::
127127
@@ -143,7 +143,8 @@ def read_pickle(
143143
144144
Returns
145145
-------
146-
same type as object stored in file
146+
object
147+
The unpickled pandas object (or any object) that was stored in file.
147148
148149
See Also
149150
--------
@@ -162,7 +163,7 @@ def read_pickle(
162163
--------
163164
>>> original_df = pd.DataFrame(
164165
... {{"foo": range(5), "bar": range(5, 10)}}
165-
... ) # doctest: +SKIP
166+
... ) # doctest: +SKIP
166167
>>> original_df # doctest: +SKIP
167168
foo bar
168169
0 0 5

pandas/tests/io/test_sql.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2229,12 +2229,14 @@ def test_api_chunksize_read(conn, request):
22292229
@pytest.mark.parametrize("conn", all_connectable)
22302230
def test_api_categorical(conn, request):
22312231
if conn == "postgresql_adbc_conn":
2232-
request.node.add_marker(
2233-
pytest.mark.xfail(
2234-
reason="categorical dtype not implemented for ADBC postgres driver",
2235-
strict=True,
2232+
adbc = import_optional_dependency("adbc_driver_postgresql", errors="ignore")
2233+
if adbc is not None and Version(adbc.__version__) < Version("0.9.0"):
2234+
request.node.add_marker(
2235+
pytest.mark.xfail(
2236+
reason="categorical dtype not implemented for ADBC postgres driver",
2237+
strict=True,
2238+
)
22362239
)
2237-
)
22382240
# GH8624
22392241
# test that categorical gets written correctly as dense column
22402242
conn = request.getfixturevalue(conn)

scripts/tests/test_validate_docstrings.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,6 @@ def test_bad_docstrings(self, capsys, klass, func, msgs) -> None:
199199
for msg in msgs:
200200
assert msg in " ".join([err[1] for err in result["errors"]])
201201

202-
def test_leftover_files_raises(self) -> None:
203-
with pytest.raises(Exception, match="The following files"):
204-
validate_docstrings.pandas_validate(
205-
self._import_path(klass="BadDocstrings", func="leftover_files")
206-
)
207-
208202
def test_validate_all_ignore_functions(self, monkeypatch) -> None:
209203
monkeypatch.setattr(
210204
validate_docstrings,

scripts/validate_docstrings.py

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import argparse
1919
import doctest
2020
import importlib
21-
import io
2221
import json
2322
import os
2423
import pathlib
@@ -28,15 +27,12 @@
2827

2928
import matplotlib
3029
import matplotlib.pyplot as plt
31-
import numpy
3230
from numpydoc.docscrape import get_doc_object
3331
from numpydoc.validate import (
3432
Validator,
3533
validate,
3634
)
3735

38-
import pandas
39-
4036
# With template backend, matplotlib plots nothing
4137
matplotlib.use("template")
4238

@@ -63,7 +59,6 @@
6359
"GL05": "Use 'array-like' rather than 'array_like' in docstrings.",
6460
"SA05": "{reference_name} in `See Also` section does not need `pandas` "
6561
"prefix, use {right_reference} instead.",
66-
"EX02": "Examples do not pass tests:\n{doctest_log}",
6762
"EX03": "flake8 error: line {line_number}, col {col_number}: {error_code} "
6863
"{error_message}",
6964
"EX04": "Do not import {imported_library}, as it is imported "
@@ -167,32 +162,6 @@ def name(self):
167162
def mentioned_private_classes(self):
168163
return [klass for klass in PRIVATE_CLASSES if klass in self.raw_doc]
169164

170-
@property
171-
def examples_errors(self):
172-
flags = doctest.NORMALIZE_WHITESPACE | doctest.IGNORE_EXCEPTION_DETAIL
173-
finder = doctest.DocTestFinder()
174-
runner = doctest.DocTestRunner(optionflags=flags)
175-
context = {"np": numpy, "pd": pandas}
176-
error_msgs = ""
177-
current_dir = set(os.listdir())
178-
for test in finder.find(self.raw_doc, self.name, globs=context):
179-
f = io.StringIO()
180-
runner.run(test, out=f.write)
181-
error_msgs += f.getvalue()
182-
leftovers = set(os.listdir()).difference(current_dir)
183-
if leftovers:
184-
for leftover in leftovers:
185-
path = pathlib.Path(leftover).resolve()
186-
if path.is_dir():
187-
path.rmdir()
188-
elif path.is_file():
189-
path.unlink(missing_ok=True)
190-
raise Exception(
191-
f"The following files were leftover from the doctest: "
192-
f"{leftovers}. Please use # doctest: +SKIP"
193-
)
194-
return error_msgs
195-
196165
@property
197166
def examples_source_code(self):
198167
lines = doctest.DocTestParser().get_examples(self.raw_doc)
@@ -290,12 +259,6 @@ def pandas_validate(func_name: str):
290259

291260
result["examples_errs"] = ""
292261
if doc.examples:
293-
result["examples_errs"] = doc.examples_errors
294-
if result["examples_errs"]:
295-
result["errors"].append(
296-
pandas_error("EX02", doctest_log=result["examples_errs"])
297-
)
298-
299262
for error_code, error_message, line_number, col_number in doc.validate_pep8():
300263
result["errors"].append(
301264
pandas_error(

0 commit comments

Comments
 (0)