grass
grass copied to clipboard
libpython: add to/from numpy functions
This PR would add two New functions:
- to parse e.g. stdout into a numpy array and
- to write a numpy array to a table in the DB backend
I would very much appreciate thorough review of the two functions, esp. the one writing to DB. Also hints on how to properly add examples for doctest (or other unit-tests) would be very welcome...
See also: https://trac.osgeo.org/grass/ticket/3639
In this PR you are using the python interface to SQLite3 and PG. Have you tested the alternative using db.execute? The reason I am asking is that the GRASS db drivers have a lot of error handling that might be missing from the python interfaces to the respective DB drivers. Using the python interfaces could case cryptic errors if something goes wrong that might be better explained by the GRASS db drivers.
Also hints on how to properly add examples for doctest (or other unit-tests) would be very welcome...
Any general Python testing instructions should be applicable like this or this. You should probably focus just on SQLite, because PostgreSQL is more difficult to set up for the tests (although it is possible).
If working within NC SPM location won't work for you tests, you can try to write plain Python unittest test and use e.g. --exec to run GRASS (the testing framework is from the times before --exec, so it does not integrate with it well, but I already had to use this approach here).
In this PR you are using the python interface to SQLite3 and PG. Have you tested the alternative using db.execute?
I have not tested. The python interfaces offer some additional functionality and direct translation between Python objects and database data types. DB handling in pygrass (where these functions are supposed to end up) also uses Python DB adapters. But It is a good point to double check that potential errors are caught properly!
@ninsbl: would you mind to rebase this PR?