Skip to content

DOC: remove private parameters from method/constructor signatures #52019

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/series_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 15 additions & 0 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import inspect
import logging
import os
import re
import sys
import warnings

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/groupby/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")


Expand Down
6 changes: 3 additions & 3 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -387,15 +387,15 @@ 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:
self.name = name
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")
Expand Down