Skip to content

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