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

Issue with flatten function when some records contain nested values and others are blank #22

Open
allanw opened this issue Sep 25, 2019 · 1 comment

Comments

@allanw
Copy link

allanw commented Sep 25, 2019

The flatten function (

def flatten(d, parent_key='', sep='__'):
) will return a dictionary with the correctly flattened values if a nested value exists. However, if another record in the same input source contains the same key and is blank, the recursive call to flatten will not return anything, and so that key will not be present in the return value.

In the example above, the dictionaries returned from flatten will have different numbers of keys, which causes a problem when writing the output to a CSV (i.e. the number of columns will differ).

@abij
Copy link

abij commented Mar 19, 2020

I think you need to flatten, since it's going to be persisted into a CSV-file.
I ran into same issue, having more fields. I fixed this by by appending new discovered headers on the end of the header. And replace the header at the end of the stream #27.

Maybe this will help you too.

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

2 participants