grass.script: Automatically parse JSON and CSV in parse_command#3687
grass.script: Automatically parse JSON and CSV in parse_command#3687petrasovaa merged 4 commits intoOSGeo:mainfrom
Conversation
wenzeslaus
left a comment
There was a problem hiding this comment.
Great update overall. The heuristic should work well the format parameter which in combination with the parse_command function will almost always refer to output text format.
A short change for what it accomplishes!
Thanks for changing to csv.DictReader, the purpose here is convenience, so DictReader seems more appropriate than plain reader.
I agree with converting the generator to a list. json.loads also returns plain objects, so it is consistent with that.
>>> type(json.loads("""{"a": 1}"""))
<class 'dict'>
>>> type(json.loads("""[1,2]"""))
<class 'list'>The delimiter change is a good clean up.
Please, add tests.
wenzeslaus
left a comment
There was a problem hiding this comment.
Thanks for the tests! They nicely show how powerful this is.
python/grass/script/testsuite/test_start_command_functions_nc.py
Outdated
Show resolved
Hide resolved
wenzeslaus
left a comment
There was a problem hiding this comment.
Awesome. Looking forward to using this. It will work great together with the JSON GSoC project.
Given several tools have options
format, this adds automatic parsing toparse_command:For csv, I use DictReader, which makes sense only when the csv has a header, but that seems like reasonable assumption, and then it works nicely with pandas.
Option delimiter does not fit well into it conceptually, so I deprecated it. Also, it's now taken into account only when parameter
parseis not specified, it assumed that anyway.