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

I met bug when my csv header began with comma #138

Open
zyxbest opened this issue Jul 11, 2017 · 0 comments
Open

I met bug when my csv header began with comma #138

zyxbest opened this issue Jul 11, 2017 · 0 comments

Comments

@zyxbest
Copy link

zyxbest commented Jul 11, 2017

situation

When I upload a file like this,the first header is '' since the line begins with comma.(See the up left empty cell)
image

Then DataPusher raise error as The data was invalid (for example: a numeric value is out of range or was inserted into a text field).

debug

The directly reason of the error is headers_dicts in DataPusher:
I log the headers_dicts then it shows:

[
    {
        'type': u'numeric',
        'id': u'name'
    },
    {
        'type': u'text',
        'id': u'total'
    },
    {
        'type': u'numeric',
        'id': u'male_share'
    },
    {
        'type': u'numeric',
        'id': u'female_share'
    },
    {
        'type': u'numeric',
        'id': u'gap'
    }
]

Obviously there is some shifting thing cuz the name should be text and the total should be numeric

I read the code :
1. offset, headers = messytables.headers_guess(row_set.sample)
2. types = messytables.type_guess(row_set.sample, types=TYPES, strict=False)
The first empty header would be stored as u'',It's totally fine.
Here len(types)==len(headers)
3. headers = [header.strip() for header in headers if header.strip()]
Then this line dropped the u'',but didn't drop correspond type, that is ,len(types)== len(headers) -1

4. `headers_dicts = [dict(id=field[0], type=TYPE_MAPPING[str(field[1])]) for field in zip(headers, types)]`

Finally in this line we get a wrong headers_dicts, zipfunc would not raise error even if parameters have different length.

@zyxbest zyxbest changed the title I met bug when my csv header begins with comma I met bug when my csv header began with comma Jul 11, 2017
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

No branches or pull requests

1 participant