Giter Site home page Giter Site logo

Comments (3)

derinwalters avatar derinwalters commented on June 16, 2024 1

Nice find! Looks like a bug in the missing column insertion logic that occurs when multiple columns not in the schema, in this case "col_b" and "col_c", are positioned after the missing column location in the dataframe to be validated. Thank you for the great working example. I'll submit a pull request shortly.

from pandera.

r-terada avatar r-terada commented on June 16, 2024

Thank you for the investigation and quick fix!
I'm waiting for your pull request to be merged :)

from pandera.

aphorton avatar aphorton commented on June 16, 2024

First, thank you very much for this fantastic package.

The code in OP's example runs as intended now for pandera 0.18.0, but adding non-unique column names causes a similar column-duplication problem.

import pandas as pd
import pandera as pa

schema = pa.DataFrameSchema(
    {
        "col_a": pa.Column(str),
        "col_missing": pa.Column(str, nullable=True)
    },
    add_missing_columns=True
)

df = pd.DataFrame({
    "col_a": ["a", "b", "c"],
    "col_b": ["d", "e", "f"]
})

print(schema.validate(df))
# -> works well
#   col_a col_missing col_b
# 0     a        None     d
# 1     b        None     e
# 2     c        None     f

df.columns = ["col_a", "col_a"]
print(schema.validate(df))
# -> duplicates columns
#   col_a col_a col_missing col_a col_a
# 0     a     d        None     a     d
# 1     b     e        None     b     e
# 2     c     f        None     c     f

Expected behavior

add only 1 col_missing
#   col_a col_a col_missing
# 0     a     d        None
# 1     b     e        None
# 2     c     f        None

from pandera.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.