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 support for aliases #329

Merged
merged 3 commits into from
Nov 25, 2020
Merged

Conversation

jeffzi
Copy link
Collaborator

@jeffzi jeffzi commented Nov 23, 2020

This PR adds support for aliases in SchemaModel and closes #324.

Example:

    import pandera as pa
    import pandas as pd

    class Schema(pa.SchemaModel):
        col_2020: pa.typing.Series[int] = pa.Field(alias=2020)
        idx: pa.typing.Index[int] = pa.Field(alias="_idx", check_name=True)

        @pa.check(2020)
        def int_column_lt_100(cls, series):
            return series < 100


    df = pd.DataFrame({2020: [99]}, index=[0])
    df.index.name = "_idx"

    Schema.validate(df)

I also restructured the schema construction. I replaced the internal attribute __fields_annotations__ by __fields__ which is a dict indexed by public column/index name (i.e. optionally aliased) and values are tuples of (AnnotationInfo, FieldInfo). That gives us more flexibility.

@codecov-io
Copy link

codecov-io commented Nov 24, 2020

Codecov Report

Merging #329 (58472dd) into master (ac41212) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #329   +/-   ##
=======================================
  Coverage   98.79%   98.80%           
=======================================
  Files          18       18           
  Lines        1747     1750    +3     
=======================================
+ Hits         1726     1729    +3     
  Misses         21       21           
Impacted Files Coverage Δ
pandera/decorators.py 100.00% <100.00%> (ø)
pandera/model.py 100.00% <100.00%> (ø)
pandera/model_components.py 100.00% <100.00%> (ø)
pandera/typing.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 ac41212...58472dd. Read the comment docs.

Copy link
Collaborator

@cosmicBboy cosmicBboy left a comment

Choose a reason for hiding this comment

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

🔥 thanks @jeffzi! this functionality keeps getting better and better :)

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.

SchemaModel support for columns which are not valid python variable names
3 participants