dataset-examples icon indicating copy to clipboard operation
dataset-examples copied to clipboard

json_to_csv_converter.py has a small issue for the new yelp dataset

Open akhodadadi opened this issue 6 years ago • 1 comments

For the file business.json, there are records (for example the 4th record) where for example the key hours exists but its value is None. This causes an exception in the function get_nested_value.

To fix it, I suggest to add the following to that function before the last line (return get_nested_value(sub_dict, sub_key)):

if sub_dict is None: return None

akhodadadi avatar Aug 17 '18 00:08 akhodadadi

@akhodadadi just came up on this. This is what worked for me.

def get_nested_value(d, key):
    """Return a dictionary item given a dictionary `d` and a flattened key from `get_column_names`.
    
    Example:

        d = {
            'a': {
                'b': 2,
                'c': 3,
                },
        }
        key = 'a.b'

        will return: 2
    
    """
    if '.' not in key:
        if key not in d:
            return None
        return d[key]
    base_key, sub_key = key.split('.', 1)
    if base_key not in d:
        return None
    sub_dict = d[base_key]
    if sub_dict is None:
        return None
    return get_nested_value(sub_dict, sub_key)

I know nothing about python so Thank You.

idkjs avatar Aug 20 '18 11:08 idkjs