Skip to content

Commit a0784d2

Browse files
authored
REF: Remove dynamic docstrings from option methods (#57710)
* REF: Remove dynamic docstrings from option methods * Fix arguments * Reuse * Fix drop duplicate section, numpydoc valudation * Fix formatting
1 parent 038976e commit a0784d2

File tree

17 files changed

+234
-303
lines changed

17 files changed

+234
-303
lines changed

pandas/_config/config.py

+200-266
Large diffs are not rendered by default.

pandas/core/arrays/arrow/_arrow_utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import numpy as np
66
import pyarrow
77

8-
from pandas._config.config import _get_option
8+
from pandas._config.config import get_option
99

1010
from pandas.errors import PerformanceWarning
1111
from pandas.util._exceptions import find_stack_level
@@ -16,7 +16,7 @@ def fallback_performancewarning(version: str | None = None) -> None:
1616
Raise a PerformanceWarning for falling back to ExtensionArray's
1717
non-pyarrow method
1818
"""
19-
if _get_option("performance_warnings"):
19+
if get_option("performance_warnings"):
2020
msg = "Falling back on a non-pyarrow code path which may decrease performance."
2121
if version is not None:
2222
msg += f" Upgrade to pyarrow >={version} to possibly suppress this warning."

pandas/core/arrays/datetimelike.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
import numpy as np
2222

23-
from pandas._config.config import _get_option
23+
from pandas._config.config import get_option
2424

2525
from pandas._libs import (
2626
algos,
@@ -1336,7 +1336,7 @@ def _addsub_object_array(self, other: npt.NDArray[np.object_], op) -> np.ndarray
13361336
# If both 1D then broadcasting is unambiguous
13371337
return op(self, other[0])
13381338

1339-
if _get_option("performance_warnings"):
1339+
if get_option("performance_warnings"):
13401340
warnings.warn(
13411341
"Adding/subtracting object-dtype array to "
13421342
f"{type(self).__name__} not vectorized.",

pandas/core/arrays/datetimes.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import numpy as np
1717

18-
from pandas._config.config import _get_option
18+
from pandas._config.config import get_option
1919

2020
from pandas._libs import (
2121
lib,
@@ -820,7 +820,7 @@ def _add_offset(self, offset: BaseOffset) -> Self:
820820
# "dtype[Any] | type[Any] | _SupportsDType[dtype[Any]]"
821821
res_values = res_values.view(values.dtype) # type: ignore[arg-type]
822822
except NotImplementedError:
823-
if _get_option("performance_warnings"):
823+
if get_option("performance_warnings"):
824824
warnings.warn(
825825
"Non-vectorized DateOffset being applied to Series or "
826826
"DatetimeIndex.",

pandas/core/arrays/sparse/array.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import numpy as np
2020

21-
from pandas._config.config import _get_option
21+
from pandas._config.config import get_option
2222

2323
from pandas._libs import lib
2424
import pandas._libs.sparse as splib
@@ -1158,7 +1158,7 @@ def searchsorted(
11581158
side: Literal["left", "right"] = "left",
11591159
sorter: NumpySorter | None = None,
11601160
) -> npt.NDArray[np.intp] | np.intp:
1161-
if _get_option("performance_warnings"):
1161+
if get_option("performance_warnings"):
11621162
msg = "searchsorted requires high memory usage."
11631163
warnings.warn(msg, PerformanceWarning, stacklevel=find_stack_level())
11641164
v = np.asarray(v)

pandas/core/arrays/string_arrow.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import numpy as np
1414

15-
from pandas._config.config import _get_option
15+
from pandas._config.config import get_option
1616

1717
from pandas._libs import (
1818
lib,
@@ -345,7 +345,7 @@ def _str_contains(
345345
self, pat, case: bool = True, flags: int = 0, na=np.nan, regex: bool = True
346346
):
347347
if flags:
348-
if _get_option("mode.performance_warnings"):
348+
if get_option("mode.performance_warnings"):
349349
fallback_performancewarning()
350350
return super()._str_contains(pat, case, flags, na, regex)
351351

@@ -406,7 +406,7 @@ def _str_replace(
406406
regex: bool = True,
407407
):
408408
if isinstance(pat, re.Pattern) or callable(repl) or not case or flags:
409-
if _get_option("mode.performance_warnings"):
409+
if get_option("mode.performance_warnings"):
410410
fallback_performancewarning()
411411
return super()._str_replace(pat, repl, n, case, flags, regex)
412412

pandas/core/computation/align.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import numpy as np
1717

18-
from pandas._config.config import _get_option
18+
from pandas._config.config import get_option
1919

2020
from pandas.errors import PerformanceWarning
2121
from pandas.util._exceptions import find_stack_level
@@ -127,7 +127,7 @@ def _align_core(terms):
127127

128128
ordm = np.log10(max(1, abs(reindexer_size - term_axis_size)))
129129
if (
130-
_get_option("performance_warnings")
130+
get_option("performance_warnings")
131131
and ordm >= 1
132132
and reindexer_size >= 10000
133133
):

pandas/core/dtypes/dtypes.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import numpy as np
2222
import pytz
2323

24-
from pandas._config.config import _get_option
24+
from pandas._config.config import get_option
2525

2626
from pandas._libs import (
2727
lib,
@@ -2030,7 +2030,7 @@ def _get_common_dtype(self, dtypes: list[DtypeObj]) -> DtypeObj | None:
20302030

20312031
# np.nan isn't a singleton, so we may end up with multiple
20322032
# NaNs here, so we ignore the all NA case too.
2033-
if _get_option("performance_warnings") and (
2033+
if get_option("performance_warnings") and (
20342034
not (len(set(fill_values)) == 1 or isna(fill_values).all())
20352035
):
20362036
warnings.warn(

pandas/core/frame.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -6506,15 +6506,15 @@ def drop_duplicates(
65066506
DataFrame or None
65076507
DataFrame with duplicates removed or None if ``inplace=True``.
65086508
6509-
Notes
6510-
-------
6511-
This method requires columns specified by ``subset`` to be of hashable type.
6512-
Passing unhashable columns will raise a ``TypeError``.
6513-
65146509
See Also
65156510
--------
65166511
DataFrame.value_counts: Count unique combinations of columns.
65176512
6513+
Notes
6514+
-----
6515+
This method requires columns specified by ``subset`` to be of hashable type.
6516+
Passing unhashable columns will raise a ``TypeError``.
6517+
65186518
Examples
65196519
--------
65206520
Consider dataset containing ramen rating.

pandas/core/indexes/multi.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import numpy as np
2222

2323
from pandas._config import get_option
24-
from pandas._config.config import _get_option
2524

2625
from pandas._libs import (
2726
algos as libalgos,
@@ -2380,7 +2379,7 @@ def drop( # type: ignore[override]
23802379
step = loc.step if loc.step is not None else 1
23812380
inds.extend(range(loc.start, loc.stop, step))
23822381
elif com.is_bool_indexer(loc):
2383-
if _get_option("performance_warnings") and self._lexsort_depth == 0:
2382+
if get_option("performance_warnings") and self._lexsort_depth == 0:
23842383
warnings.warn(
23852384
"dropping on a non-lexsorted multi-index "
23862385
"without a level parameter may impact performance.",
@@ -3042,7 +3041,7 @@ def _maybe_to_slice(loc):
30423041
if not follow_key:
30433042
return slice(start, stop)
30443043

3045-
if _get_option("performance_warnings"):
3044+
if get_option("performance_warnings"):
30463045
warnings.warn(
30473046
"indexing past lexsort depth may impact performance.",
30483047
PerformanceWarning,

pandas/core/internals/managers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import numpy as np
2020

21-
from pandas._config.config import _get_option
21+
from pandas._config.config import get_option
2222

2323
from pandas._libs import (
2424
algos as libalgos,
@@ -1529,7 +1529,7 @@ def insert(self, loc: int, item: Hashable, value: ArrayLike, refs=None) -> None:
15291529
self._known_consolidated = False
15301530

15311531
if (
1532-
_get_option("performance_warnings")
1532+
get_option("performance_warnings")
15331533
and sum(not block.is_extension for block in self.blocks) > 100
15341534
):
15351535
warnings.warn(

pandas/core/reshape/reshape.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import numpy as np
1212

13-
from pandas._config.config import _get_option
13+
from pandas._config.config import get_option
1414

1515
import pandas._libs.reshape as libreshape
1616
from pandas.errors import PerformanceWarning
@@ -146,7 +146,7 @@ def __init__(
146146
num_cells = num_rows * num_columns
147147

148148
# GH 26314: Previous ValueError raised was too restrictive for many users.
149-
if _get_option("performance_warnings") and num_cells > np.iinfo(np.int32).max:
149+
if get_option("performance_warnings") and num_cells > np.iinfo(np.int32).max:
150150
warnings.warn(
151151
f"The following operation may generate {num_cells} cells "
152152
f"in the resulting pandas object.",

pandas/io/excel/_base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1131,7 +1131,7 @@ def __new__(
11311131
ext = "xlsx"
11321132

11331133
try:
1134-
engine = config.get_option(f"io.excel.{ext}.writer", silent=True)
1134+
engine = config.get_option(f"io.excel.{ext}.writer")
11351135
if engine == "auto":
11361136
engine = get_default_engine(ext, mode="writer")
11371137
except KeyError as err:
@@ -1552,7 +1552,7 @@ def __init__(
15521552
"an engine manually."
15531553
)
15541554

1555-
engine = config.get_option(f"io.excel.{ext}.reader", silent=True)
1555+
engine = config.get_option(f"io.excel.{ext}.reader")
15561556
if engine == "auto":
15571557
engine = get_default_engine(ext, mode="reader")
15581558

pandas/io/formats/info.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ def __init__(
622622
@property
623623
def max_rows(self) -> int:
624624
"""Maximum info rows to be displayed."""
625-
return get_option("display.max_info_rows", len(self.data) + 1)
625+
return get_option("display.max_info_rows")
626626

627627
@property
628628
def exceeds_info_cols(self) -> bool:
@@ -641,7 +641,7 @@ def col_count(self) -> int:
641641

642642
def _initialize_max_cols(self, max_cols: int | None) -> int:
643643
if max_cols is None:
644-
return get_option("display.max_info_columns", self.col_count + 1)
644+
return get_option("display.max_info_columns")
645645
return max_cols
646646

647647
def _initialize_show_counts(self, show_counts: bool | None) -> bool:

pandas/io/pytables.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
get_option,
3232
using_pyarrow_string_dtype,
3333
)
34-
from pandas._config.config import _get_option
3534

3635
from pandas._libs import (
3736
lib,
@@ -3149,7 +3148,7 @@ def write_array(
31493148
pass
31503149
elif inferred_type == "string":
31513150
pass
3152-
elif _get_option("performance_warnings"):
3151+
elif get_option("performance_warnings"):
31533152
ws = performance_doc % (inferred_type, key, items)
31543153
warnings.warn(ws, PerformanceWarning, stacklevel=find_stack_level())
31553154

pandas/tests/config/test_config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ def f3(key):
395395
assert cf.get_option("a") == 500
396396

397397
cf.reset_option("a")
398-
assert options.a == cf.get_option("a", 0)
398+
assert options.a == cf.get_option("a")
399399

400400
msg = "You can only set the value of existing options"
401401
with pytest.raises(OptionError, match=msg):

pandas/tests/plotting/test_converter.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -114,18 +114,17 @@ def test_matplotlib_formatters(self):
114114

115115
def test_option_no_warning(self):
116116
pytest.importorskip("matplotlib.pyplot")
117-
ctx = cf.option_context("plotting.matplotlib.register_converters", False)
118117
plt = pytest.importorskip("matplotlib.pyplot")
119118
s = Series(range(12), index=date_range("2017", periods=12))
120119
_, ax = plt.subplots()
121120

122121
# Test without registering first, no warning
123-
with ctx:
122+
with cf.option_context("plotting.matplotlib.register_converters", False):
124123
ax.plot(s.index, s.values)
125124

126125
# Now test with registering
127126
register_matplotlib_converters()
128-
with ctx:
127+
with cf.option_context("plotting.matplotlib.register_converters", False):
129128
ax.plot(s.index, s.values)
130129
plt.close()
131130

0 commit comments

Comments
 (0)