Skip to content

Commit

Permalink
Add sqrt, log, sin, cos and tan transform primitives (#1948)
Browse files Browse the repository at this point in the history
* added sqrt, log, sin, cos and tan primitives

* update release notes

* fix typo

* fix example output

* fix example output 2

* changed return_type

Co-authored-by: Nate Parsons <4307001+thehomebrewnerd@users.noreply.github.com>
  • Loading branch information
tvdboom and thehomebrewnerd committed Mar 15, 2022
1 parent 9d59bed commit 61876c8
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 1 deletion.
5 changes: 5 additions & 0 deletions docs/source/api_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ General Transform Primitives
:toctree: generated/

Absolute
SquareRoot
NaturalLogarithm
Sine
Cosine
Tangent
Percentile
TimeSince

Expand Down
3 changes: 2 additions & 1 deletion docs/source/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Release Notes
Future Release
==============
* Enhancements
* Added the SquareRoot, NaturalLogarithm, Sine, Cosine and Tangent primitives (:pr:`1948`)
* Fixes
* Updated the conda install commands to specify the channel (:pr:`1917`)
* Changes
Expand All @@ -26,7 +27,7 @@ Future Release
* Add lower bound for wheel for minimum dependency checker and limit lint CI tests to Python 3.10 (:pr:`1945`)

Thanks to the following people for contributing to this release:
:user:`tamargrey`, :user:`kushal-gopal`, :user:`rwedge`, :user:`mingdavidqi`, :user:`andriyor`, :user:`thehomebrewnerd`
:user:`tamargrey`, :user:`kushal-gopal`, :user:`rwedge`, :user:`mingdavidqi`, :user:`andriyor`, :user:`thehomebrewnerd`, :user:`tvdboom`

Breaking Changes
++++++++++++++++
Expand Down
91 changes: 91 additions & 0 deletions featuretools/primitives/standard/transform_primitive.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Boolean,
BooleanNullable,
Categorical,
Double,
EmailAddress,
NaturalLanguage
)
Expand Down Expand Up @@ -53,6 +54,96 @@ def get_function(self):
return np.absolute


class SquareRoot(TransformPrimitive):
"""Computes the square root of a number.
Examples:
>>> sqrt = SquareRoot()
>>> sqrt([9.0, 16.0, 4.0]).tolist()
[3.0, 4.0, 2.0]
"""
name = "square_root"
input_types = [ColumnSchema(semantic_tags={'numeric'})]
return_type = ColumnSchema(logical_type=Double, semantic_tags={'numeric'})
compatibility = [Library.PANDAS, Library.DASK, Library.KOALAS]
description_template = "the square root of {}"

def get_function(self):
return np.sqrt


class NaturalLogarithm(TransformPrimitive):
"""Computes the natural logarithm of a number.
Examples:
>>> log = NaturalLogarithm()
>>> log([1.0, np.e]).tolist()
[0.0, 1.0]
"""
name = "natural_logarithm"
input_types = [ColumnSchema(semantic_tags={'numeric'})]
return_type = ColumnSchema(logical_type=Double, semantic_tags={'numeric'})
compatibility = [Library.PANDAS, Library.DASK, Library.KOALAS]
description_template = "the natural logarithm of {}"

def get_function(self):
return np.log


class Sine(TransformPrimitive):
"""Computes the sine of a number.
Examples:
>>> sin = Sine()
>>> sin([-np.pi/2.0, 0.0, np.pi/2.0]).tolist()
[-1.0, 0.0, 1.0]
"""
name = "sine"
input_types = [ColumnSchema(semantic_tags={'numeric'})]
return_type = ColumnSchema(logical_type=Double, semantic_tags={'numeric'})
compatibility = [Library.PANDAS, Library.DASK, Library.KOALAS]
description_template = "the sine of {}"

def get_function(self):
return np.sin


class Cosine(TransformPrimitive):
"""Computes the cosine of a number.
Examples:
>>> cos = Cosine()
>>> cos([0.0, np.pi/2.0, np.pi]).tolist()
[1.0, 6.123233995736766e-17, -1.0]
"""
name = "cosine"
input_types = [ColumnSchema(semantic_tags={'numeric'})]
return_type = ColumnSchema(logical_type=Double, semantic_tags={'numeric'})
compatibility = [Library.PANDAS, Library.DASK, Library.KOALAS]
description_template = "the cosine of {}"

def get_function(self):
return np.cos


class Tangent(TransformPrimitive):
"""Computes the tangent of a number.
Examples:
>>> tan = Tangent()
>>> tan([-np.pi, 0.0, np.pi/2.0]).tolist()
[1.2246467991473532e-16, 0.0, 1.633123935319537e+16]
"""
name = "tangent"
input_types = [ColumnSchema(semantic_tags={'numeric'})]
return_type = ColumnSchema(logical_type=Double, semantic_tags={'numeric'})
compatibility = [Library.PANDAS, Library.DASK, Library.KOALAS]
description_template = "the tangent of {}"

def get_function(self):
return np.tan


class NumCharacters(TransformPrimitive):
"""Calculates the number of characters in a string.
Expand Down

0 comments on commit 61876c8

Please sign in to comment.