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

Update data_preproc_functions.py to solve conversion to float issue #498

Merged
merged 2 commits into from
Oct 11, 2023

Conversation

baraldian
Copy link
Contributor

Solving issue 497 when converting values to float due to deprecation of float function in numpy.

#497 (comment)

Using pandas built in functions to optimize time.
Proof:

timeit.timeit("df['age'].apply(lambda x: float(x >= 26))", number=10, setup="import pandas as pd;df = pd.DataFrame({'age':range(1000000)})")
2.8678155599627644
timeit.timeit("(df['age'] >= 26).astype(float)", number=10, setup="import pandas as pd;df = pd.DataFrame({'age':range(1000000)})")
0.01317960600135848
((df['age'] >= 26).astype(float) == df['age'].apply(lambda x: float(x >= 26))).all()
True

Solving issue 497 when converting values to float due to deprecation of float function in numpy.

 Trusted-AI#497 (comment) 

Using pandas built in functions to optimize time.
Proof:
timeit.timeit("df['age'].apply(lambda x: float(x >= 26))", number=10, setup="import pandas as pd;df = pd.DataFrame({'age':range(1000000)})")
>>> 2.8678155599627644
timeit.timeit("(df['age'] >= 26).astype(float)", number=10, setup="import pandas as pd;df = pd.DataFrame({'age':range(1000000)})")
>>> 0.01317960600135848
((df['age'] >= 26).astype(float) == df['age'].apply(lambda x: float(x >= 26))).all()
>>> True

Signed-off-by: Andrea Baraldi <baraldian@gmail.com>
@hoffmansc hoffmansc linked an issue Oct 11, 2023 that may be closed by this pull request
@hoffmansc hoffmansc self-requested a review October 11, 2023 15:19
Signed-off-by: Samuel Hoffman <hoffman.sc@gmail.com>
Copy link
Collaborator

@hoffmansc hoffmansc left a comment

Choose a reason for hiding this comment

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

Nice work!

@hoffmansc hoffmansc merged commit 2572fcb into Trusted-AI:master Oct 11, 2023
5 of 9 checks passed
@PrimozGodec
Copy link

Thank you for the fix. @hoffmansc, can a new release be made soon since it is causing issues on Numpy from 1.24? It is causing conflicts with some packages.

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.

AttributeError: module 'numpy' has no attribute 'float'.
3 participants