Giter Site home page Giter Site logo

csv-schema-py's People

Contributors

hafen avatar pcstout avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

csv-schema-py's Issues

Add some optional constraints to columns

It would be nice to have the ability to:

  • not authorize additional columns (like the additionalItems of json-schema)
  • force column order

With these two options, it even becomes possible to omit the column names, as only their places in the row can be used.

For instance:

{
"additional_columns": false,
"column_order": true
}

Optional columns fail data validation

When a non-required column is not present, header validation succeeds but data validation fails with a KeyError. This is because the validator accesses the dictionary entry for the column whether or not the column is actually present.

The patch is fairly simple, and I am setting up a pull request for you. I would appreciate if you can accept and deploy a new version.

Accept custom dialects

First of all, thanks for this package it’s great!

My problem is that the validator only accepts “classic” CSV with a header, a comma as separator, a newline with \n, etc.

It would be really nice to manage other formats, and even nicer to make these formats part of the schema.

To manage formats, here are some ideas:

  • Use the Dialects of the native csv library.
  • In this line which reads the CSV file, give a custom dialect to DictReader.
  • The custom dialect could either be given as an argument of ValidateCsv.__init__, or could be generated from the schema itself. In that last case, a new method generate_dialect could parse the schema and build the dialect.

Example of schema with maximum complexity for the dialect:

{
  "name": null,
  "description": null,
  "filename": {
    "regex": null
  },
  "dialect": {
    "delimiter": "\t",
    "skipinitialspace": true,
    "lineterminator": "\n",
    "quoting": "QUOTE_NONE",
    "quotechar": "'",
    "escapechar": "\\",
    "doublequote": false
  }
  "columns": []
}

I’ll try to do a PR if I can spare some time.

Make some attributes optional

Maybe it was intentional that attributes are mandatory. But I think some of them can have a default value to null.

If one does not want to check the filename, one does not necessarily want to write the whole filename object in my schema.

min and max could also have a default value equal to null.

I think the following attributes must be mandatory:

  • name (for the main object and colum objects)
  • type (for colum objects)
  • columns (for the main object)

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.