From c1ce139befee4da2e0a3db92364c34ccd6134675 Mon Sep 17 00:00:00 2001 From: Jordan Murphy <35613487+jordan-d-murphy@users.noreply.github.com> Date: Mon, 22 Jan 2024 22:55:20 -0600 Subject: [PATCH 1/2] DOC: fix EX03 errors in docstrings - pandas.Series.plot.line, pandas.Series.to_sql, pandas.read_json, pandas.DataFrame.to_sql --- ci/code_checks.sh | 6 +----- pandas/core/generic.py | 16 +++++++++------- pandas/io/json/_json.py | 6 +++--- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index e7509760bfde9..8dc7f8463e5af 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -70,11 +70,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then RET=$(($RET + $?)) ; echo $MSG "DONE" MSG='Partially validate docstrings (EX03)' ; echo $MSG - $BASE_DIR/scripts/validate_docstrings.py --format=actions --errors=EX03 --ignore_functions \ - pandas.Series.plot.line \ - pandas.Series.to_sql \ - pandas.read_json \ - pandas.DataFrame.to_sql # There should be no backslash in the final line, please keep this comment in the last ignored function + $BASE_DIR/scripts/validate_docstrings.py --format=actions --errors=EX03 RET=$(($RET + $?)) ; echo $MSG "DONE" MSG='Partially validate docstrings (PR02)' ; echo $MSG diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 2fe1f4a3bcf7c..a3729a3649efb 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -2999,7 +2999,7 @@ def to_sql( 3 >>> from sqlalchemy import text >>> with engine.connect() as conn: - ... conn.execute(text("SELECT * FROM users")).fetchall() + ... conn.execute(text("SELECT * FROM users")).fetchall() [(0, 'User 1'), (1, 'User 2'), (2, 'User 3')] An `sqlalchemy.engine.Connection` can also be passed to `con`: @@ -3016,7 +3016,7 @@ def to_sql( >>> df2.to_sql(name='users', con=engine, if_exists='append') 2 >>> with engine.connect() as conn: - ... conn.execute(text("SELECT * FROM users")).fetchall() + ... conn.execute(text("SELECT * FROM users")).fetchall() [(0, 'User 1'), (1, 'User 2'), (2, 'User 3'), (0, 'User 4'), (1, 'User 5'), (0, 'User 6'), (1, 'User 7')] @@ -3027,7 +3027,7 @@ def to_sql( ... index_label='id') 2 >>> with engine.connect() as conn: - ... conn.execute(text("SELECT * FROM users")).fetchall() + ... conn.execute(text("SELECT * FROM users")).fetchall() [(0, 'User 6'), (1, 'User 7')] Use ``method`` to define a callable insertion method to do nothing @@ -3040,13 +3040,14 @@ def to_sql( ... stmt = insert(table.table).values(data).on_conflict_do_nothing(index_elements=["a"]) ... result = conn.execute(stmt) ... return result.rowcount - >>> df_conflict.to_sql(name="conflict_table", con=conn, if_exists="append", method=insert_on_conflict_nothing) # doctest: +SKIP + >>> df_conflict.to_sql(name="conflict_table", con=conn, if_exists="append", # noqa: F821 + ... method=insert_on_conflict_nothing) # doctest: +SKIP 0 For MySQL, a callable to update columns ``b`` and ``c`` if there's a conflict on a primary key. - >>> from sqlalchemy.dialects.mysql import insert + >>> from sqlalchemy.dialects.mysql import insert # noqa: F811 >>> def insert_on_conflict_update(table, conn, keys, data_iter): ... # update columns "b" and "c" on primary key conflict ... data = [dict(zip(keys, row)) for row in data_iter] @@ -3057,7 +3058,8 @@ def to_sql( ... stmt = stmt.on_duplicate_key_update(b=stmt.inserted.b, c=stmt.inserted.c) ... result = conn.execute(stmt) ... return result.rowcount - >>> df_conflict.to_sql(name="conflict_table", con=conn, if_exists="append", method=insert_on_conflict_update) # doctest: +SKIP + >>> df_conflict.to_sql(name="conflict_table", con=conn, if_exists="append", # noqa: F821 + ... method=insert_on_conflict_update) # doctest: +SKIP 2 Specify the dtype (especially useful for integers with missing values). @@ -3078,7 +3080,7 @@ def to_sql( 3 >>> with engine.connect() as conn: - ... conn.execute(text("SELECT * FROM integers")).fetchall() + ... conn.execute(text("SELECT * FROM integers")).fetchall() [(1,), (None,), (2,)] """ # noqa: E501 from pandas.io import sql diff --git a/pandas/io/json/_json.py b/pandas/io/json/_json.py index 4c490c6b2cda2..594fb8651f8f0 100644 --- a/pandas/io/json/_json.py +++ b/pandas/io/json/_json.py @@ -717,7 +717,7 @@ def read_json( "data":[["a","b"],["c","d"]]\ }}\ ' - >>> pd.read_json(StringIO(_), orient='split') + >>> pd.read_json(StringIO(_), orient='split') # noqa: F821 col 1 col 2 row 1 a b row 2 c d @@ -727,7 +727,7 @@ def read_json( >>> df.to_json(orient='index') '{{"row 1":{{"col 1":"a","col 2":"b"}},"row 2":{{"col 1":"c","col 2":"d"}}}}' - >>> pd.read_json(StringIO(_), orient='index') + >>> pd.read_json(StringIO(_), orient='index') # noqa: F821 col 1 col 2 row 1 a b row 2 c d @@ -737,7 +737,7 @@ def read_json( >>> df.to_json(orient='records') '[{{"col 1":"a","col 2":"b"}},{{"col 1":"c","col 2":"d"}}]' - >>> pd.read_json(StringIO(_), orient='records') + >>> pd.read_json(StringIO(_), orient='records') # noqa: F821 col 1 col 2 0 a b 1 c d From d8b66734a93268c0f997ad0e829ccd104b2fc368 Mon Sep 17 00:00:00 2001 From: Jordan Murphy <35613487+jordan-d-murphy@users.noreply.github.com> Date: Tue, 23 Jan 2024 01:13:36 -0600 Subject: [PATCH 2/2] removed EX03 specific block, and added EX03 to "Validate docstrings" block --- ci/code_checks.sh | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 5f2f04569fd75..c0a26edd230eb 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -65,12 +65,8 @@ fi ### DOCSTRINGS ### if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then - 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" - - MSG='Partially validate docstrings (EX03)' ; echo $MSG - $BASE_DIR/scripts/validate_docstrings.py --format=actions --errors=EX03 + MSG='Validate docstrings (EX01, EX03, 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,EX03,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" MSG='Partially validate docstrings (PR02)' ; echo $MSG