gmr / flatdict

Python module for interacting with nested dicts as a single level dict with delimited keys.
https://flatdict.readthedocs.io
BSD 3-Clause "New" or "Revised" License
112 stars 32 forks source link

Add ability for method to return dict instances which can contain li… #10

Closed AleksanderGondek closed 7 years ago

AleksanderGondek commented 7 years ago

Allow as_dict method to return dict instances containing lists.

Function added: If appropriate flag is set while instantiating FlatDict (as_dict_list_awareness=True) the as_dict method will no longer return dictionary with lists converted to dicts – instead it will contain lists.

Example:

# Dictionary containg dicts nested in list
document = {
    "eloquent": [
        {
            "frosty": "dijkstra",
            "happy": "dubinsky"
        }
    ]
}

import flatdict
old_flatdict = flatdict.FlatDict(document)
dict.as_dict()

Out: {'eloquent': ['dijkstra', 'dubinsky']}
# Information is lost and the dict structure is not preserved!

old_flatdict = flatdict.FlatDict(document, as_dict_list_awareness=True)
dict.as_dict()

Out: {'eloquent':[{'frosty':'dijkstra','happy':'dubinsky'}]}
# Information was not lost, dict structure is preserved.

Rationale: I am currently using FlatDict as a wrapper for objects read directly from JSON format – this makes many operations easier. However, currently there is no way to return to initial structure of document and save it back to JSON – with this change it becomes possible.

codecov-io commented 7 years ago

Codecov Report

:exclamation: No coverage uploaded for pull request base (master@0bdeb7c). Click here to learn what that means. The diff coverage is 84%.

@@            Coverage Diff            @@
##             master      #10   +/-   ##
=========================================
  Coverage          ?   96.29%           
=========================================
  Files             ?        1           
  Lines             ?      162           
  Branches          ?        0           
=========================================
  Hits              ?      156           
  Misses            ?        6           
  Partials          ?        0
Impacted Files Coverage Δ
flatdict.py 96.29% <84%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 0bdeb7c...946eeff. Read the comment docs.

AleksanderGondek commented 7 years ago

@gmr Hm.. This is my first time dealing with codecov.io - is there anything I can do to fix this error ? Because from what I can tell, its root is that the master branch has no codecoverage file.