Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REF: Remove dynamic docstrings from option methods #57710

Merged
merged 10 commits into from
Mar 6, 2024
466 changes: 200 additions & 266 deletions pandas/_config/config.py

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pandas/core/arrays/arrow/_arrow_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import numpy as np
import pyarrow

from pandas._config.config import _get_option
from pandas._config.config import get_option

from pandas.errors import PerformanceWarning
from pandas.util._exceptions import find_stack_level
Expand All @@ -16,7 +16,7 @@ def fallback_performancewarning(version: str | None = None) -> None:
Raise a PerformanceWarning for falling back to ExtensionArray's
non-pyarrow method
"""
if _get_option("performance_warnings"):
if get_option("performance_warnings"):
msg = "Falling back on a non-pyarrow code path which may decrease performance."
if version is not None:
msg += f" Upgrade to pyarrow >={version} to possibly suppress this warning."
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/arrays/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import numpy as np

from pandas._config.config import _get_option
from pandas._config.config import get_option

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

if _get_option("performance_warnings"):
if get_option("performance_warnings"):
warnings.warn(
"Adding/subtracting object-dtype array to "
f"{type(self).__name__} not vectorized.",
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/arrays/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import numpy as np

from pandas._config.config import _get_option
from pandas._config.config import get_option

from pandas._libs import (
lib,
Expand Down Expand Up @@ -820,7 +820,7 @@ def _add_offset(self, offset: BaseOffset) -> Self:
# "dtype[Any] | type[Any] | _SupportsDType[dtype[Any]]"
res_values = res_values.view(values.dtype) # type: ignore[arg-type]
except NotImplementedError:
if _get_option("performance_warnings"):
if get_option("performance_warnings"):
warnings.warn(
"Non-vectorized DateOffset being applied to Series or "
"DatetimeIndex.",
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/arrays/sparse/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import numpy as np

from pandas._config.config import _get_option
from pandas._config.config import get_option

from pandas._libs import lib
import pandas._libs.sparse as splib
Expand Down Expand Up @@ -1158,7 +1158,7 @@ def searchsorted(
side: Literal["left", "right"] = "left",
sorter: NumpySorter | None = None,
) -> npt.NDArray[np.intp] | np.intp:
if _get_option("performance_warnings"):
if get_option("performance_warnings"):
msg = "searchsorted requires high memory usage."
warnings.warn(msg, PerformanceWarning, stacklevel=find_stack_level())
v = np.asarray(v)
Expand Down
6 changes: 3 additions & 3 deletions pandas/core/arrays/string_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import numpy as np

from pandas._config.config import _get_option
from pandas._config.config import get_option

from pandas._libs import (
lib,
Expand Down Expand Up @@ -345,7 +345,7 @@ def _str_contains(
self, pat, case: bool = True, flags: int = 0, na=np.nan, regex: bool = True
):
if flags:
if _get_option("mode.performance_warnings"):
if get_option("mode.performance_warnings"):
fallback_performancewarning()
return super()._str_contains(pat, case, flags, na, regex)

Expand Down Expand Up @@ -406,7 +406,7 @@ def _str_replace(
regex: bool = True,
):
if isinstance(pat, re.Pattern) or callable(repl) or not case or flags:
if _get_option("mode.performance_warnings"):
if get_option("mode.performance_warnings"):
fallback_performancewarning()
return super()._str_replace(pat, repl, n, case, flags, regex)

Expand Down
4 changes: 2 additions & 2 deletions pandas/core/computation/align.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import numpy as np

from pandas._config.config import _get_option
from pandas._config.config import get_option

from pandas.errors import PerformanceWarning
from pandas.util._exceptions import find_stack_level
Expand Down Expand Up @@ -127,7 +127,7 @@ def _align_core(terms):

ordm = np.log10(max(1, abs(reindexer_size - term_axis_size)))
if (
_get_option("performance_warnings")
get_option("performance_warnings")
and ordm >= 1
and reindexer_size >= 10000
):
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/dtypes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import numpy as np
import pytz

from pandas._config.config import _get_option
from pandas._config.config import get_option

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

# np.nan isn't a singleton, so we may end up with multiple
# NaNs here, so we ignore the all NA case too.
if _get_option("performance_warnings") and (
if get_option("performance_warnings") and (
not (len(set(fill_values)) == 1 or isna(fill_values).all())
):
warnings.warn(
Expand Down
10 changes: 5 additions & 5 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -6506,15 +6506,15 @@ def drop_duplicates(
DataFrame or None
DataFrame with duplicates removed or None if ``inplace=True``.

Notes
-------
This method requires columns specified by ``subset`` to be of hashable type.
Passing unhashable columns will raise a ``TypeError``.

See Also
--------
DataFrame.value_counts: Count unique combinations of columns.

Notes
-----
This method requires columns specified by ``subset`` to be of hashable type.
Passing unhashable columns will raise a ``TypeError``.

Examples
--------
Consider dataset containing ramen rating.
Expand Down
5 changes: 2 additions & 3 deletions pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import numpy as np

from pandas._config import get_option
from pandas._config.config import _get_option

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

if _get_option("performance_warnings"):
if get_option("performance_warnings"):
warnings.warn(
"indexing past lexsort depth may impact performance.",
PerformanceWarning,
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import numpy as np

from pandas._config.config import _get_option
from pandas._config.config import get_option

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

if (
_get_option("performance_warnings")
get_option("performance_warnings")
and sum(not block.is_extension for block in self.blocks) > 100
):
warnings.warn(
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/reshape/reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import numpy as np

from pandas._config.config import _get_option
from pandas._config.config import get_option

import pandas._libs.reshape as libreshape
from pandas.errors import PerformanceWarning
Expand Down Expand Up @@ -146,7 +146,7 @@ def __init__(
num_cells = num_rows * num_columns

# GH 26314: Previous ValueError raised was too restrictive for many users.
if _get_option("performance_warnings") and num_cells > np.iinfo(np.int32).max:
if get_option("performance_warnings") and num_cells > np.iinfo(np.int32).max:
warnings.warn(
f"The following operation may generate {num_cells} cells "
f"in the resulting pandas object.",
Expand Down
4 changes: 2 additions & 2 deletions pandas/io/excel/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@ def __new__(
ext = "xlsx"

try:
engine = config.get_option(f"io.excel.{ext}.writer", silent=True)
engine = config.get_option(f"io.excel.{ext}.writer")
if engine == "auto":
engine = get_default_engine(ext, mode="writer")
except KeyError as err:
Expand Down Expand Up @@ -1552,7 +1552,7 @@ def __init__(
"an engine manually."
)

engine = config.get_option(f"io.excel.{ext}.reader", silent=True)
engine = config.get_option(f"io.excel.{ext}.reader")
if engine == "auto":
engine = get_default_engine(ext, mode="reader")

Expand Down
4 changes: 2 additions & 2 deletions pandas/io/formats/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ def __init__(
@property
def max_rows(self) -> int:
"""Maximum info rows to be displayed."""
return get_option("display.max_info_rows", len(self.data) + 1)
rhshadrach marked this conversation as resolved.
Show resolved Hide resolved
return get_option("display.max_info_rows")

@property
def exceeds_info_cols(self) -> bool:
Expand All @@ -641,7 +641,7 @@ def col_count(self) -> int:

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

def _initialize_show_counts(self, show_counts: bool | None) -> bool:
Expand Down
3 changes: 1 addition & 2 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
get_option,
using_pyarrow_string_dtype,
)
from pandas._config.config import _get_option

from pandas._libs import (
lib,
Expand Down Expand Up @@ -3149,7 +3148,7 @@ def write_array(
pass
elif inferred_type == "string":
pass
elif _get_option("performance_warnings"):
elif get_option("performance_warnings"):
ws = performance_doc % (inferred_type, key, items)
warnings.warn(ws, PerformanceWarning, stacklevel=find_stack_level())

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/config/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ def f3(key):
assert cf.get_option("a") == 500

cf.reset_option("a")
assert options.a == cf.get_option("a", 0)
assert options.a == cf.get_option("a")

msg = "You can only set the value of existing options"
with pytest.raises(OptionError, match=msg):
Expand Down
5 changes: 2 additions & 3 deletions pandas/tests/plotting/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,17 @@ def test_matplotlib_formatters(self):

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

# Test without registering first, no warning
with ctx:
with cf.option_context("plotting.matplotlib.register_converters", False):
ax.plot(s.index, s.values)

# Now test with registering
register_matplotlib_converters()
with ctx:
with cf.option_context("plotting.matplotlib.register_converters", False):
ax.plot(s.index, s.values)
plt.close()

Expand Down