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 DistanceToHoliday transform primitive #1853

Merged
merged 27 commits into from
Jan 21, 2022
Merged

Conversation

dvreed77
Copy link
Contributor

@dvreed77 dvreed77 self-assigned this Jan 20, 2022
@@ -1078,3 +1080,85 @@ def date_to_holiday(x):
df = df.merge(holidays_df, how='left')
return df.names.values
return date_to_holiday


class DistanceToHoliday(TransformPrimitive):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we try to move some of this into a utility? Since it uses similar functionality to our other primitive (DateToHoliday)?

We did this with CountString & WhiteSpaceCount

We have a primitive util file too:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, sounds good.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gsheni upon second look I think you had a good point. Let me know what you think

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, looks good.

@codecov
Copy link

codecov bot commented Jan 20, 2022

Codecov Report

Merging #1853 (2e5dcec) into main (8b1d5da) will increase coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head 2e5dcec differs from pull request most recent head 8319287. Consider uploading reports for the commit 8319287 to get more accurate results
Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1853   +/-   ##
=======================================
  Coverage   98.79%   98.80%           
=======================================
  Files         143      144    +1     
  Lines       15916    15984   +68     
=======================================
+ Hits        15725    15793   +68     
  Misses        191      191           
Impacted Files Coverage Δ
...retools/primitives/standard/transform_primitive.py 100.00% <100.00%> (ø)
featuretools/primitives/utils.py 99.38% <100.00%> (+0.05%) ⬆️
...imitive_tests/test_distancetoholiday_primitives.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8b1d5da...8319287. Read the comment docs.

@dvreed77 dvreed77 changed the title WIP Add DistanceToHoliday TransformPrimitive Add DistanceToHoliday TransformPrimitive Jan 21, 2022
@gsheni gsheni changed the title Add DistanceToHoliday TransformPrimitive Add DistanceToHoliday transform primitive Jan 21, 2022
np.testing.assert_array_equal(given_answer, answer)


def test_valid_country():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the original version of this test was perhaps testing something slightly different since it was named test_holiday_out_of_range, but I'm not exactly clear now what the intent of that test was. Do you have any ideas? I see the original test introduced np.nan values in the result, but this one does not.

Copy link
Contributor Author

@dvreed77 dvreed77 Jan 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thehomebrewnerd I dug into this a bit. The test above isn't replacing that test, I actually didn't see the original tests when moving things over.

The out of range test you mentioned brought to my attention some unexpected behavior when using the holidays library. It appears the observed holidays are only present in the dataset. For example, the test date of 2010-1-1 results in a NaN because there is no holiday named "Boxing Day" in the data set for 2009 and 2010 since they fall on Saturday and Sunday respectively. Instead, the dataset contains "Boxing Day (Observed)".

I think this is confusing behavior in my opinion.

cc: @gsheni


distance_list = distance_to_holiday(dates).tolist()

assert distance_list[0] == 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor suggestion, but can we create a list of expected values and assert the same way we do in test_nat and test_valid_country instead of checking each value individually?

@dvreed77 dvreed77 merged commit b3e4101 into main Jan 21, 2022
@dvreed77 dvreed77 deleted the 1847-distance-to-holiday branch January 22, 2022 23:15
@dvreed77 dvreed77 mentioned this pull request Feb 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add DistanceToHoliday primitive
3 participants