From 84fa8368ffb082c7f67d04907dc36ee31eebc3ef Mon Sep 17 00:00:00 2001 From: skirui-source Date: Tue, 23 Feb 2021 18:44:53 -0800 Subject: [PATCH 1/3] bug fix issue: PYTHONOPTIMIZE=2 --- python/cudf/cudf/utils/docutils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/cudf/cudf/utils/docutils.py b/python/cudf/cudf/utils/docutils.py index a4c35d0459a..a04162f2db1 100644 --- a/python/cudf/cudf/utils/docutils.py +++ b/python/cudf/cudf/utils/docutils.py @@ -27,7 +27,7 @@ def docfmt(**kwargs): def outer(fn): buf = [] - formatsiter = string.Formatter().parse(fn.__doc__) + formatsiter = string.Formatter().parse(fn.__doc__)# for literal, field, fmtspec, conv in formatsiter: assert conv is None assert not fmtspec From 30d4f60b359a172472cb3d33eb244566cc1750c1 Mon Sep 17 00:00:00 2001 From: Sheilah Date: Thu, 25 Feb 2021 09:00:13 -0800 Subject: [PATCH 2/3] added case for when __doc__ is not None --- python/cudf/cudf/core/dataframe.py | 9 ++++---- python/cudf/cudf/utils/docutils.py | 35 +++++++++++++++--------------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/python/cudf/cudf/core/dataframe.py b/python/cudf/cudf/core/dataframe.py index 3e7e6625abe..1ae051d4514 100644 --- a/python/cudf/cudf/core/dataframe.py +++ b/python/cudf/cudf/core/dataframe.py @@ -7528,10 +7528,11 @@ def merge(left, right, *args, **kwargs): # a bit of fanciness to inject docstring with left parameter merge_doc = DataFrame.merge.__doc__ -idx = merge_doc.find("right") -merge.__doc__ = "".join( - [merge_doc[:idx], "\n\tleft : DataFrame\n\t", merge_doc[idx:]] -) +if merge_doc is not None: + idx = merge_doc.find("right") + merge.__doc__ = "".join( + [merge_doc[:idx], "\n\tleft : DataFrame\n\t", merge_doc[idx:]] + ) def _align_indices(lhs, rhs): diff --git a/python/cudf/cudf/utils/docutils.py b/python/cudf/cudf/utils/docutils.py index a04162f2db1..037515e8ea8 100644 --- a/python/cudf/cudf/utils/docutils.py +++ b/python/cudf/cudf/utils/docutils.py @@ -27,23 +27,24 @@ def docfmt(**kwargs): def outer(fn): buf = [] - formatsiter = string.Formatter().parse(fn.__doc__)# - for literal, field, fmtspec, conv in formatsiter: - assert conv is None - assert not fmtspec - buf.append(literal) - if field is not None: - # get indentation - lines = literal.rsplit("\n", 1) - if _only_spaces(lines[-1]): - indent = " " * len(lines[-1]) - valuelines = kwargs[field].splitlines(True) - # first line - buf.append(valuelines[0]) - # subsequent lines are indented - buf.extend([indent + ln for ln in valuelines[1:]]) - else: - buf.append(kwargs[field]) + if fn.__doc__ is not None: + formatsiter = string.Formatter().parse(fn.__doc__) + for literal, field, fmtspec, conv in formatsiter: + assert conv is None + assert not fmtspec + buf.append(literal) + if field is not None: + # get indentation + lines = literal.rsplit("\n", 1) + if _only_spaces(lines[-1]): + indent = " " * len(lines[-1]) + valuelines = kwargs[field].splitlines(True) + # first line + buf.append(valuelines[0]) + # subsequent lines are indented + buf.extend([indent + ln for ln in valuelines[1:]]) + else: + buf.append(kwargs[field]) fn.__doc__ = "".join(buf) return fn From 3cdec51a5dad840551aa3d3e9624709591bbe9b2 Mon Sep 17 00:00:00 2001 From: Sheilah Date: Thu, 25 Feb 2021 13:52:28 -0800 Subject: [PATCH 3/3] fixed indentation --- python/cudf/cudf/utils/docutils.py | 38 +++++++++++++++--------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/python/cudf/cudf/utils/docutils.py b/python/cudf/cudf/utils/docutils.py index 037515e8ea8..57ad612846d 100644 --- a/python/cudf/cudf/utils/docutils.py +++ b/python/cudf/cudf/utils/docutils.py @@ -27,25 +27,25 @@ def docfmt(**kwargs): def outer(fn): buf = [] - if fn.__doc__ is not None: - formatsiter = string.Formatter().parse(fn.__doc__) - for literal, field, fmtspec, conv in formatsiter: - assert conv is None - assert not fmtspec - buf.append(literal) - if field is not None: - # get indentation - lines = literal.rsplit("\n", 1) - if _only_spaces(lines[-1]): - indent = " " * len(lines[-1]) - valuelines = kwargs[field].splitlines(True) - # first line - buf.append(valuelines[0]) - # subsequent lines are indented - buf.extend([indent + ln for ln in valuelines[1:]]) - else: - buf.append(kwargs[field]) - + if fn.__doc__ is None: + return fn + formatsiter = string.Formatter().parse(fn.__doc__) + for literal, field, fmtspec, conv in formatsiter: + assert conv is None + assert not fmtspec + buf.append(literal) + if field is not None: + # get indentation + lines = literal.rsplit("\n", 1) + if _only_spaces(lines[-1]): + indent = " " * len(lines[-1]) + valuelines = kwargs[field].splitlines(True) + # first line + buf.append(valuelines[0]) + # subsequent lines are indented + buf.extend([indent + ln for ln in valuelines[1:]]) + else: + buf.append(kwargs[field]) fn.__doc__ = "".join(buf) return fn