Skip to content

Commit

Permalink
Add inconsistencies keyword to derived_from (#9192)
Browse files Browse the repository at this point in the history
  • Loading branch information
avriiil committed Jun 22, 2022
1 parent 0820983 commit 8323ee9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
5 changes: 4 additions & 1 deletion dask/dataframe/accessor.py
Expand Up @@ -272,7 +272,10 @@ 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="``expand=True`` with unknown ``n`` will raise a ``NotImplementedError``",
)
def split(self, pat=None, n=-1, expand=False):
"""Known inconsistencies: ``expand=True`` with unknown ``n`` will raise a ``NotImplementedError``."""
return self._split("split", pat=pat, n=n, expand=expand)
Expand Down
27 changes: 22 additions & 5 deletions dask/utils.py
Expand Up @@ -666,7 +666,7 @@ def extra_titles(doc):
return "\n".join(lines)


def ignore_warning(doc, cls, name, extra="", skipblocks=0):
def ignore_warning(doc, cls, name, extra="", skipblocks=0, inconsistencies=None):
"""Expand docstring by adding disclaimer and extra text"""
import inspect

Expand Down Expand Up @@ -697,7 +697,11 @@ 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]
if inconsistencies is not None:
l3 = f"Known inconsistencies: \n {inconsistencies}"
bits = [head, indent, l1, l2, "\n\n", l3, "\n\n"] + more + [tail]
else:
bits = [head, indent, l1, indent, l2, "\n\n"] + more + [tail]
doc = "".join(bits)

return doc
Expand All @@ -718,7 +722,9 @@ 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,7 +754,12 @@ 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"
Expand All @@ -771,7 +782,9 @@ 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=None
):
"""Decorator to attach original class's docstring to the wrapped method.
The output structure will be: top line of docstring, disclaimer about this
Expand All @@ -791,6 +804,9 @@ def derived_from(original_klass, version=None, ua_args=None, skipblocks=0):
skipblocks : int
How many text blocks (paragraphs) to skip from the start of the
docstring. Useful for cases where the target has extra front-matter.
inconsistencies: list
List of known inconsistencies with method whose docstrings are being
copied.
"""
ua_args = ua_args or []

Expand All @@ -803,6 +819,7 @@ def wrapper(method):
ua_args=ua_args,
extra=extra,
skipblocks=skipblocks,
inconsistencies=inconsistencies,
)
return method

Expand Down

0 comments on commit 8323ee9

Please sign in to comment.