From c5c309a5e58b8c6b29ae877de8379f90a67ec4a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dea=20Mar=C3=ADa=20L=C3=A9on?= Date: Thu, 27 Jul 2023 19:18:44 +0200 Subject: [PATCH 1/4] PerformanceWarning example --- ci/code_checks.sh | 1 - pandas/errors/__init__.py | 22 ++++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index dd9219f03abca..6ec41a153dc7d 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -63,7 +63,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then MSG='Partially validate docstrings (EX01)' ; echo $MSG $BASE_DIR/scripts/validate_docstrings.py --format=actions --errors=EX01 --ignore_functions \ - pandas.errors.PerformanceWarning \ pandas.errors.PyperclipException \ pandas.errors.PyperclipWindowsException \ pandas.errors.UnsortedIndexError \ diff --git a/pandas/errors/__init__.py b/pandas/errors/__init__.py index 71e12109292ae..3555dd7d9ee14 100644 --- a/pandas/errors/__init__.py +++ b/pandas/errors/__init__.py @@ -46,6 +46,28 @@ class NullFrequencyError(ValueError): class PerformanceWarning(Warning): """ Warning raised when there is a possible performance impact. + + + Examples + -------- + >>> df = pd.DataFrame({"jim": [0, 0, 1, 1], + ... "joe": ["x", "x", "z", "y"], + ... "jolie": [1, 2, 3, 4]}) + >>> df = df.set_index(["jim", "joe"]) + >>> df + jolie + jim joe + 0 x 1 + x 2 + 1 z 3 + y 4 + >>> df.loc[(1, 'z')] + Traceback (most recent call last): + PerformanceWarning: indexing past lexsort depth may impact performance. + df.loc[(1, 'z')]) + jolie + jim joe + 1 z 3 """ From 4b644b4045f34f57ab17e97e2067952d53fd521c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dea=20Mar=C3=ADa=20L=C3=A9on?= Date: Fri, 28 Jul 2023 10:10:38 +0200 Subject: [PATCH 2/4] Removed extra line --- pandas/errors/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/errors/__init__.py b/pandas/errors/__init__.py index 3555dd7d9ee14..277e95285f934 100644 --- a/pandas/errors/__init__.py +++ b/pandas/errors/__init__.py @@ -47,7 +47,6 @@ class PerformanceWarning(Warning): """ Warning raised when there is a possible performance impact. - Examples -------- >>> df = pd.DataFrame({"jim": [0, 0, 1, 1], From 0be2fa0780bff731d724085c8fa5129e56fe2b1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dea=20Mar=C3=ADa=20L=C3=A9on?= Date: Fri, 28 Jul 2023 10:14:20 +0200 Subject: [PATCH 3/4] Clean-up output --- pandas/errors/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/errors/__init__.py b/pandas/errors/__init__.py index 277e95285f934..6152a8d224247 100644 --- a/pandas/errors/__init__.py +++ b/pandas/errors/__init__.py @@ -63,7 +63,7 @@ class PerformanceWarning(Warning): >>> df.loc[(1, 'z')] Traceback (most recent call last): PerformanceWarning: indexing past lexsort depth may impact performance. - df.loc[(1, 'z')]) + df.loc[(1, 'z')] jolie jim joe 1 z 3 From f1eaa8bf9a1303a5ff2479fd78144a713bad0360 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dea=20Mar=C3=ADa=20L=C3=A9on?= Date: Fri, 28 Jul 2023 10:56:41 +0200 Subject: [PATCH 4/4] skip doctest as warnings are suppressed --- pandas/errors/__init__.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pandas/errors/__init__.py b/pandas/errors/__init__.py index 6152a8d224247..a7d113094543d 100644 --- a/pandas/errors/__init__.py +++ b/pandas/errors/__init__.py @@ -60,9 +60,8 @@ class PerformanceWarning(Warning): x 2 1 z 3 y 4 - >>> df.loc[(1, 'z')] - Traceback (most recent call last): - PerformanceWarning: indexing past lexsort depth may impact performance. + >>> df.loc[(1, 'z')] # doctest: +SKIP + # PerformanceWarning: indexing past lexsort depth may impact performance. df.loc[(1, 'z')] jolie jim joe