diff --git a/asv_bench/benchmarks/series_methods.py b/asv_bench/benchmarks/series_methods.py index 204393cbb76f2..83d10d22352cd 100644 --- a/asv_bench/benchmarks/series_methods.py +++ b/asv_bench/benchmarks/series_methods.py @@ -29,7 +29,7 @@ def time_constructor_no_data(self): Series(data=None, index=self.idx) def time_constructor_fastpath(self): - Series(self.array, index=self.idx2, name="name", fastpath=True) + Series(self.array, index=self.idx2, name="name", _fastpath=True) class ToFrame: diff --git a/doc/source/conf.py b/doc/source/conf.py index 6671cefae9073..eb50cec9aa238 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -14,6 +14,7 @@ import inspect import logging import os +import re import sys import warnings @@ -765,6 +766,19 @@ def process_business_alias_docstrings(app, what, name, obj, options, lines): lines[:] = [] +def process_signature(app, what, name, obj, options, signature, return_annotation): + """ + Remove all the private (starting with underscore) parameters from the signature + of class constructors and other functions. + """ + if signature: + # matches parameters starting with underscore `_` + pattern = r",[\s\t]*_[a-zA-Z0-9_:\s=]*" + + signature_without_private_args = re.sub(pattern, "", signature) + return (signature_without_private_args, return_annotation) + + suppress_warnings = [ # We "overwrite" autosummary with our PandasAutosummary, but # still want the regular autosummary setup to run. So we just @@ -795,6 +809,7 @@ def setup(app): app.connect("autodoc-process-docstring", remove_flags_docstring) app.connect("autodoc-process-docstring", process_class_docstrings) app.connect("autodoc-process-docstring", process_business_alias_docstrings) + app.connect("autodoc-process-signature", process_signature) app.add_autodocumenter(AccessorDocumenter) app.add_autodocumenter(AccessorAttributeDocumenter) app.add_autodocumenter(AccessorMethodDocumenter) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index c2ee684751b5f..b393bcbaa295c 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -4277,7 +4277,7 @@ def _box_col_values(self, values: SingleDataManager, loc: int) -> Series: name = self.columns[loc] klass = self._constructor_sliced # We get index=self.index bc values is a SingleDataManager - return klass(values, name=name, fastpath=True).__finalize__(self) + return klass(values, name=name, _fastpath=True).__finalize__(self) # ---------------------------------------------------------------------- # Lookup Caching @@ -4924,7 +4924,7 @@ def _sanitize_column(self, value) -> ArrayLike: def _series(self): return { item: Series( - self._mgr.iget(idx), index=self.index, name=item, fastpath=True + self._mgr.iget(idx), index=self.index, name=item, _fastpath=True ) for idx, item in enumerate(self.columns) } diff --git a/pandas/core/groupby/ops.py b/pandas/core/groupby/ops.py index 0acc7fe29b5db..e6f8821018eca 100644 --- a/pandas/core/groupby/ops.py +++ b/pandas/core/groupby/ops.py @@ -1274,7 +1274,7 @@ class SeriesSplitter(DataSplitter): def _chop(self, sdata: Series, slice_obj: slice) -> Series: # fastpath equivalent to `sdata.iloc[slice_obj]` mgr = sdata._mgr.get_slice(slice_obj) - ser = sdata._constructor(mgr, name=sdata.name, fastpath=True) + ser = sdata._constructor(mgr, name=sdata.name, _fastpath=True) return ser.__finalize__(sdata, method="groupby") diff --git a/pandas/core/series.py b/pandas/core/series.py index b0958869c67f3..c174349e459bc 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -377,7 +377,7 @@ def __init__( dtype: Dtype | None = None, name=None, copy: bool = False, - fastpath: bool = False, + _fastpath: bool = False, ) -> None: if ( isinstance(data, (SingleBlockManager, SingleArrayManager)) @@ -387,7 +387,7 @@ def __init__( ): # GH#33357 called with just the SingleBlockManager NDFrame.__init__(self, data) - if fastpath: + if _fastpath: # e.g. from _box_col_values, skip validation of name object.__setattr__(self, "_name", name) else: @@ -395,7 +395,7 @@ def __init__( return # we are called internally, so short-circuit - if fastpath: + if _fastpath: # data is a ndarray, index is defined if not isinstance(data, (SingleBlockManager, SingleArrayManager)): manager = get_option("mode.data_manager")