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

Fix bug in PercentTrue primitive #2626

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/source/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Future Release
==============
* Enhancements
* Fixes
* Fix bug with default value in ``PercentTrue`` primitive (:pr:`2626`)
* Changes
* Refactor ``featuretools/tests/primitive_tests/utils.py`` to leverage list comprehensions for improved Pythonic quality (:pr:`2607`)
* Refactor ``can_stack_primitive_on_inputs`` (:pr:`2522`)
Expand Down
3 changes: 2 additions & 1 deletion featuretools/primitives/standard/aggregation/percent_true.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pandas as pd
from woodwork.column_schema import ColumnSchema
from woodwork.logical_types import Boolean, BooleanNullable, Double

Expand Down Expand Up @@ -30,7 +31,7 @@ class PercentTrue(AggregationPrimitive):
return_type = ColumnSchema(logical_type=Double, semantic_tags={"numeric"})
stack_on = []
stack_on_exclude = []
default_value = 0
default_value = pd.NA
compatibility = [Library.PANDAS, Library.DASK]
description_template = "the percentage of true values in {}"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import pandas as pd
from woodwork.logical_types import BooleanNullable

import featuretools as ft


def test_percent_true_default_value_with_dfs():
es = ft.EntitySet(id="customer_data")

customers_df = pd.DataFrame(data={"customer_id": [1, 2]})
transactions_df = pd.DataFrame(
data={"tx_id": [1], "customer_id": [1], "is_foo": [True]},
)

es.add_dataframe(
dataframe_name="customers_df",
dataframe=customers_df,
index="customer_id",
)
es.add_dataframe(
dataframe_name="transactions_df",
dataframe=transactions_df,
index="tx_id",
logical_types={"is_foo": BooleanNullable},
)

es = es.add_relationship(
"customers_df",
"customer_id",
"transactions_df",
"customer_id",
)

feature_matrix, _ = ft.dfs(
entityset=es,
target_dataframe_name="customers_df",
agg_primitives=["percent_true"],
)

assert pd.isna(feature_matrix["PERCENT_TRUE(transactions_df.is_foo)"][2])
Loading