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

Add inconsistencies keyword to derived_from #9192

Merged
merged 6 commits into from Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion dask/dataframe/accessor.py
Expand Up @@ -272,7 +272,7 @@ def _split(self, method, pat=None, n=-1, expand=False):
meta = (self._series.name, object)
return self._function_map(method, pat=pat, n=n, expand=expand, meta=meta)

@derived_from(pd.core.strings.StringMethods)
@derived_from(pd.core.strings.StringMethods, inconsistencies="Richard's Test Message.")
def split(self, pat=None, n=-1, expand=False):
return self._split("split", pat=pat, n=n, expand=expand)

Expand Down
25 changes: 19 additions & 6 deletions dask/utils.py
Expand Up @@ -666,8 +666,10 @@ def extra_titles(doc):
return "\n".join(lines)


def ignore_warning(doc, cls, name, extra="", skipblocks=0):
"""Expand docstring by adding disclaimer and extra text"""
def ignore_warning(doc, cls, name, extra="", skipblocks=0, inconsistencies=[]):
"""Expand docstring by adding disclaimer and extra text
Inconsistencies: list of strings reporting known inconsistencies with method whose docstring is being copied.
"""
import inspect

if inspect.isclass(cls):
Expand All @@ -679,6 +681,13 @@ def ignore_warning(doc, cls, name, extra="", skipblocks=0):
else:
l1 = f"This docstring was copied from {cls.__name__}.{name}.\n\n"
l2 = "Some inconsistencies with the Dask version may exist."

inconsistencies = None

if inconsistencies:
l3 = f"Known inconsistencies: \n {inconsistencies}"
else:
l3 = ""

i = doc.find("\n\n")
if i != -1:
Expand All @@ -697,7 +706,7 @@ def ignore_warning(doc, cls, name, extra="", skipblocks=0):
more = [indent, extra.rstrip("\n") + "\n\n"]
else:
more = []
bits = [head, indent, l1, indent, l2, "\n\n"] + more + [tail]
bits = [head, indent, l1, indent, l2, "\n", l3, "\n\n"] + more + [tail]
doc = "".join(bits)

return doc
Expand All @@ -718,7 +727,7 @@ def unsupported_arguments(doc, args):
return "\n".join(lines)


def _derived_from(cls, method, ua_args=None, extra="", skipblocks=0):
def _derived_from(cls, method, ua_args=None, extra="", skipblocks=0, inconsistencies=None):
"""Helper function for derived_from to ease testing"""
ua_args = ua_args or []

Expand Down Expand Up @@ -748,11 +757,14 @@ def _derived_from(cls, method, ua_args=None, extra="", skipblocks=0):
# Insert disclaimer that this is a copied docstring
if doc:
doc = ignore_warning(
doc, cls, method.__name__, extra=extra, skipblocks=skipblocks
doc, cls, method.__name__, extra=extra, skipblocks=skipblocks, inconsistencies=inconsistencies,
)
elif extra:
doc += extra.rstrip("\n") + "\n\n"

# Insert known inconsistencies as list of strings
inconsistencies = []

# Mark unsupported arguments
try:
method_args = get_named_args(method)
Expand All @@ -771,7 +783,7 @@ def _derived_from(cls, method, ua_args=None, extra="", skipblocks=0):
return doc


def derived_from(original_klass, version=None, ua_args=None, skipblocks=0):
def derived_from(original_klass, version=None, ua_args=None, skipblocks=0, inconsistencies):
"""Decorator to attach original class's docstring to the wrapped method.

The output structure will be: top line of docstring, disclaimer about this
Expand Down Expand Up @@ -803,6 +815,7 @@ def wrapper(method):
ua_args=ua_args,
extra=extra,
skipblocks=skipblocks,
inconsistencies=inconsistencies,
)
return method

Expand Down