MCPcopy
hub / github.com/pandas-dev/pandas / make_flex_doc

Function make_flex_doc

pandas/core/ops/docstrings.py:8–69  ·  view source on GitHub ↗

Make the appropriate substitutions for the given operation and class-typ into either _flex_doc_SERIES or _flex_doc_FRAME to return the docstring to attach to a generated method. Parameters ---------- op_name : str {'__add__', '__sub__', ... '__eq__', '__ne__', ...} typ

(op_name: str, typ: str)

Source from the content-addressed store, hash-verified

6
7
8def make_flex_doc(op_name: str, typ: str) -> str:
9 """
10 Make the appropriate substitutions for the given operation and class-typ
11 into either _flex_doc_SERIES or _flex_doc_FRAME to return the docstring
12 to attach to a generated method.
13
14 Parameters
15 ----------
16 op_name : str {'__add__', '__sub__', ... '__eq__', '__ne__', ...}
17 typ : str {series, 'dataframe']}
18
19 Returns
20 -------
21 doc : str
22 """
23 op_name = op_name.replace("__", "")
24 op_desc = _op_descriptions[op_name]
25
26 op_desc_op = op_desc["op"]
27 assert op_desc_op is not None # for mypy
28 if op_name.startswith("r"):
29 equiv = f"other {op_desc_op} {typ}"
30 elif op_name == "divmod":
31 equiv = f"{op_name}({typ}, other)"
32 else:
33 equiv = f"{typ} {op_desc_op} other"
34
35 if typ == "series":
36 base_doc = _flex_doc_SERIES
37 if op_desc["reverse"]:
38 base_doc += _see_also_reverse_SERIES.format(
39 reverse=op_desc["reverse"], see_also_desc=op_desc["see_also_desc"]
40 )
41 doc_no_examples = base_doc.format(
42 desc=op_desc["desc"],
43 op_name=op_name,
44 equiv=equiv,
45 series_returns=op_desc["series_returns"],
46 )
47 ser_example = op_desc["series_examples"]
48 if ser_example:
49 doc = doc_no_examples + ser_example
50 else:
51 doc = doc_no_examples
52 elif typ == "dataframe":
53 if op_name in ["eq", "ne", "le", "lt", "ge", "gt"]:
54 base_doc = _flex_comp_doc_FRAME
55 doc = _flex_comp_doc_FRAME.format(
56 op_name=op_name,
57 desc=op_desc["desc"],
58 )
59 else:
60 base_doc = _flex_doc_FRAME
61 doc = base_doc.format(
62 desc=op_desc["desc"],
63 op_name=op_name,
64 equiv=equiv,
65 reverse=op_desc["reverse"],

Callers

nothing calls this directly

Calls 3

startswithMethod · 0.80
replaceMethod · 0.45
formatMethod · 0.45

Tested by

no test coverage detected