grass icon indicating copy to clipboard operation
grass copied to clipboard

libpython: add to/from numpy functions

Open ninsbl opened this issue 5 years ago • 5 comments

This PR would add two New functions:

  1. to parse e.g. stdout into a numpy array and
  2. 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...

ninsbl avatar Mar 16 '20 23:03 ninsbl

See also: https://trac.osgeo.org/grass/ticket/3639

ninsbl avatar Mar 18 '20 13:03 ninsbl

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.

metzm avatar Mar 29 '20 20:03 metzm

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).

wenzeslaus avatar Apr 21 '20 19:04 wenzeslaus

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 avatar May 11 '20 08:05 ninsbl

@ninsbl: would you mind to rebase this PR?

neteler avatar Nov 07 '23 12:11 neteler