Skip to content

Commit

Permalink
Split primitive descriptions on blank line instead of first line brea…
Browse files Browse the repository at this point in the history
…k to avoid truncating descriptions (#2219)

* Split primitive descriptions on blank line instead of first line break to avoid cutting off description

* cleanup

* Add release note

* Fix broken test
  • Loading branch information
tamargrey authored Aug 4, 2022
1 parent 31d80ab commit b90cb83
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
3 changes: 2 additions & 1 deletion docs/source/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Future Release
* Update ``Trend`` and ``RollingTrend`` primitives to work with ``IntegerNullable`` inputs (:pr:`2204`)
* ``camel_and_title_to_snake`` handles snake case strings with numbers (:pr:`2220`)
* Changes
* Change ``_get_description`` to split on blank lines to avoid truncating primitive descriptions (:pr:`2219`)
* Documentation Changes
* Add instructions to add new users to featuretools feedstock (:pr:`2215`)
* Testing Changes
Expand All @@ -19,7 +20,7 @@ Future Release
* Configure codecov to avoid premature PR comments (:pr:`2209`)

Thanks to the following people for contributing to this release:
:user:`gsheni`, :user:`rwedge`, :user:`sbadithe`, :user:`thehomebrewnerd`
:user:`gsheni`, :user:`rwedge`, :user:`sbadithe`, :user:`tamargrey`, :user:`thehomebrewnerd`

v1.12.0 Jul 19, 2022
====================
Expand Down
5 changes: 4 additions & 1 deletion featuretools/primitives/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,10 @@ def _get_descriptions(primitives):
for prim in primitives:
description = ""
if prim.__doc__ is not None:
description = prim.__doc__.split("\n")[0]
# Break on the empty line between the docstring description and the remainder of the docstring
description = prim.__doc__.split("\n\n")[0]
# remove any excess whitespace from line breaks
description = " ".join(description.split())
descriptions.append(description)
return descriptions

Expand Down
51 changes: 51 additions & 0 deletions featuretools/tests/primitive_tests/test_primitive_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
Age,
Count,
Day,
Diff,
GreaterThan,
Haversine,
IsFreeEmailDomain,
IsNull,
Last,
Max,
Mean,
Expand All @@ -35,6 +37,7 @@
get_transform_primitives,
)
from featuretools.primitives.base import PrimitiveBase
from featuretools.primitives.base.transform_primitive_base import TransformPrimitive
from featuretools.primitives.utils import (
_check_input_types,
_get_descriptions,
Expand Down Expand Up @@ -93,6 +96,54 @@ def test_descriptions():
assert _get_descriptions(list(primitives.keys())) == list(primitives.values())


def test_get_descriptions_doesnt_truncate_primitive_description():
# single line
descr = _get_descriptions([IsNull])
assert descr[0] == "Determines if a value is null."

# multiple line; one sentence
descr = _get_descriptions([Diff])
assert (
descr[0]
== "Computes the difference between the value in a list and the previous value in that list."
)

# multiple lines; multiple sentences
class TestPrimitive(TransformPrimitive):
"""This is text that continues on after the line break
and ends in a period.
This is text on one line without a period
Examples:
>>> absolute = Absolute()
>>> absolute([3.0, -5.0, -2.4]).tolist()
[3.0, 5.0, 2.4]
"""

name = "test_primitive"

descr = _get_descriptions([TestPrimitive])
assert (
descr[0]
== "This is text that continues on after the line break and ends in a period. This is text on one line without a period"
)

# docstring ends after description
class TestPrimitive2(TransformPrimitive):
"""This is text that continues on after the line break
and ends in a period.
This is text on one line without a period
"""

name = "test_primitive"

descr = _get_descriptions([TestPrimitive2])
assert (
descr[0]
== "This is text that continues on after the line break and ends in a period. This is text on one line without a period"
)


def test_get_default_aggregation_primitives():
primitives = get_default_aggregation_primitives()
expected_primitives = [
Expand Down

0 comments on commit b90cb83

Please sign in to comment.