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

Let checks.has_dtypes accept functions as values of the items dict #36

Open
topper-123 opened this issue May 27, 2017 · 2 comments
Open

Comments

@topper-123
Copy link
Contributor

topper-123 commented May 27, 2017

Today is is a bit difficult to check on pandas dtypes directly. For example see below:

import numpy as np
import pandas as pd
import engarde.checks as ck

# this works because it has dtype int32
df1 = pd.DataFrame({'A':[1,2,3]}, dtype=np.int32)
df1.pipe(ck.has_dtypes, items={'A':int})

# this fails because it has dtype int64
df2 = pd.DataFrame({'A':[1,2,3]})
df2.pipe(ck.has_dtypes, items={'A':int})

To make dtype-checking more robust, I propose that the parameter items in has_dtypes can accept functions as values. This will allow us to use the functions in pandas.api.types to check dtypes which will ease dtype. checking

For example:

df2 = pd.DataFrame({'A':[1,2,3]})
df2.pipe(ck.has_dtypes, items={'A':pd.api.types.is_integer_dtype})

I have already written a proposal on this (but it needs tests). I will just push it straight away so for your review.

@abhijeetmote
Copy link

I was trying the above examples and it was not working this is the way it is working.

import numpy as np
import pandas as pd
import engarde.checks as ck

# this works because it has dtype int32
df1 = pd.DataFrame({'A':[1,2,3]}, dtype=np.int32)
df1.pipe(ck.has_dtypes, items={'A':np.int32})

# this fails because it has dtype int64
df2 = pd.DataFrame({'A':[1,2,3]})
df2.pipe(ck.has_dtypes, items={'A':np.int64})

print(df1.dtypes)
print(df2.dtypes)

@TomAugspurger
Copy link
Collaborator

TomAugspurger commented Oct 7, 2019 via email

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

No branches or pull requests

3 participants