Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sqrt, log, sin, cos and tan transform primitives #1948

Merged
merged 9 commits into from
Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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, Since, Cosine and Tangent primitives (:pr:`1948`)
tvdboom marked this conversation as resolved.
Show resolved Hide resolved
* Fixes
* Updated the conda install commands to specify the channel (:pr:`1917`)
* Changes
Expand All @@ -25,7 +26,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
90 changes: 90 additions & 0 deletions featuretools/primitives/standard/transform_primitive.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,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(semantic_tags={'numeric'})
tvdboom marked this conversation as resolved.
Show resolved Hide resolved
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, np.e**3]).tolist()
[0.0, 1.0, 3.0]
"""
name = "natural_logarithm"
input_types = [ColumnSchema(semantic_tags={'numeric'})]
return_type = ColumnSchema(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([0.0, np.pi/6.0, np.pi/2.0]).tolist()
[0.0, 0.5, 1.0]
"""
name = "sine"
input_types = [ColumnSchema(semantic_tags={'numeric'})]
return_type = ColumnSchema(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(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, np.pi/2.0, np.pi]).tolist()
[1.22460635e-16, 1.63317787e+16, -1.22460635e-16]
"""
name = "tangent"
input_types = [ColumnSchema(semantic_tags={'numeric'})]
return_type = ColumnSchema(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