Skip to content

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

@topper-123

Description

@topper-123

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions