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

Custom fieldname support #93

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

jonafato
Copy link
Collaborator

@jonafato jonafato commented Mar 9, 2024

Add support for validating CSVs that don't include a header row. The implementation allows a user to define a sequence of field names and passes these through to the underlying DictReader instances. The fieldnames attribute is None by default, which retains the existing behavior of inferring field names from a header row in the source CSV.

Resolves #88.


Example usage:

from vladiate import Vlad
from vladiate.validators import UniqueValidator, SetValidator
from vladiate.inputs import LocalFile

class CustomFieldnamesValidator(Vlad):
    source = LocalFile('vampires.csv')
    fieldnames = ['Column A', 'Column B']
    validators = {
        'Column A': [
            UniqueValidator()
        ],
        'Column B': [
            SetValidator(['Vampire', 'Not A Vampire'])
        ]
    }
Column A,Column B
Vlad the Impaler,Not A Vampire
Dracula,Vampire
Count Chocula,Vampire
» vladiate

Validating CustomFieldnamesValidator(source=LocalFile('vampires.csv'))
Passed! :)

@jonafato jonafato marked this pull request as draft March 9, 2024 20:58
@jonafato jonafato mentioned this pull request Mar 9, 2024
@di
Copy link
Owner

di commented Mar 10, 2024

Makes sense to me!

@jonafato jonafato changed the title Proof of Concept: custom fieldname support Custom fieldname support Mar 15, 2024
@jonafato jonafato marked this pull request as ready for review March 15, 2024 02:17
Add support for validating CSVs that don't include a header row. The
implementation allows a user to define a sequence of field names and
passes these through to the underlying `DictReader` instances. The
`fieldnames` attribute is `None` by default, which retains the existing
behavior of inferring field names from a header row in the source CSV.

Resolves di#88.
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.

CSV without header
2 participants