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

Unexpected type problems with has_dtype decorator #55

Open
kot-behemoth opened this issue Oct 5, 2018 · 0 comments
Open

Unexpected type problems with has_dtype decorator #55

kot-behemoth opened this issue Oct 5, 2018 · 0 comments

Comments

@kot-behemoth
Copy link

kot-behemoth commented Oct 5, 2018

First of all, I'd like to say this lib looks really good - it's simple, easy to integrate and has very usable API. I've been meaning to integrate it into my workflow for a while, and I finally got a chance to today. However, it's been an unsuccessful experience.

I'm on Windows, using Python 3.6.

I tried following the docs example for has_dtypes decorator. In short, it seems you really can't use the usual Python types in the dtype schema information. Instead of int, you have to use np.int4, and instead of str, np.object_ should be used instead.

I'd imagine this would be very confusing for newcomers, when they get assertion errors by just following the examples.

Here's a simple reprex:

import engarde.decorators as ed
import pandas as pd
import numpy as np


sample_df = pd.DataFrame([
    dict(a=1, b='test 1'),
    dict(a=2, b='test 2'),
])

expected_schema = dict(
    a=int,
    b=str
)

# I expect this to work, following the doc example. However, it fails
@ed.has_dtypes(items=expected_schema)
def expected_process(df):
    return df

# Fails with AssertionError: a has the wrong dtype (<class 'int'>)
# comment it out to see the working example below
expected_process(sample_df)


working_schema = dict(
    a=np.int64,
    b=np.object_
)

# fixed the schema
@ed.has_dtypes(items=working_schema)
def working_process(df):
    return df

# this works
working_process(sample_df)
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

1 participant