Skip to content

libpython: add to/from numpy functions #423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2,438 commits into
base: main
Choose a base branch
from
Open

Conversation

ninsbl
Copy link
Member

@ninsbl ninsbl commented Mar 16, 2020

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 ninsbl added the enhancement New feature or request label Mar 16, 2020
@ninsbl ninsbl requested review from zarch and wenzeslaus March 16, 2020 23:00
@ninsbl
Copy link
Member Author

ninsbl commented Mar 18, 2020

@metzm
Copy link
Contributor

metzm commented Mar 29, 2020

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.

@wenzeslaus
Copy link
Member

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

@ninsbl
Copy link
Member Author

ninsbl commented May 11, 2020

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!

"""
sql_to_dtype = {
"sqlite": {
"INTEGER": [0, 2, 3, 4, 5, 6, 7, 8, 9, 10],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does these really need to be numbers and not things like numpy.int32?

Comment on lines 801 to 804
insert_sql = "INSERT INTO {}({}) VALUES %s;".format(
table,
", ".join(structured_array.dtype.names),
",".join(["?"] * len(structured_array.dtype.names)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use named placeholders such as {table} and table= when there is more than one item to avoid confusion. Here seems to be some with %s and the third argument.

@neteler neteler added the Python Related code is in Python label Dec 9, 2021
@neteler neteler added this to the 8.0.1 milestone Dec 9, 2021
@ninsbl ninsbl modified the milestones: 8.0.1, 8.2.0 Feb 20, 2022
@wenzeslaus wenzeslaus modified the milestones: 8.2.0, 8.4.0 Mar 16, 2022
@wenzeslaus wenzeslaus modified the milestones: 8.3.0, 8.4.0 Feb 10, 2023
@neteler neteler changed the title add to/from numpy functions libpython: add to/from numpy functions Nov 7, 2023
@neteler
Copy link
Member

neteler commented Nov 7, 2023

@ninsbl: would you mind to rebase this PR?

@wenzeslaus wenzeslaus modified the milestones: 8.4.0, 8.5.0 Apr 26, 2024
@echoix echoix added the conflicts/needs rebase Rebase to or merge with the latest base branch is needed label Jul 3, 2024
echoix and others added 8 commits August 30, 2024 22:07
Fix dead store warning in d.linegraph module

Co-authored-by: Shubham Vasudeo Desai <[email protected]>
nix: improve nix development environment

* inherit build dependencies from grass package
* add `dev-help` function
* CI(pre-commit): Enable markdownlint fixes

* CI: Add fix: true in .markdownlint.yml for tools using that config key

* Update .markdownlint.yml

* Update v.surf.rst.html to remove trailing whitespaces
* CI: add nix package and dev environment test

* nix: exclude more files from package source

---------

Co-authored-by: Edouard Choinière <[email protected]>
@echoix echoix removed enhancement New feature or request GUI wxGUI related docker Docker related CI Continuous integration conflicts/needs rebase Rebase to or merge with the latest base branch is needed raster Related to raster data processing temporal Related to temporal data processing Python Related code is in Python C Related code is in C C++ Related code is in C++ HTML Related code is in HTML CSS Related code is in CSS database Related to database management RFC Request For Comment (RFC) document libraries module general display imagery tests Related to Test Suite raster3d notebook labels Oct 31, 2024
@echoix echoix added the conflicts/needs rebase Rebase to or merge with the latest base branch is needed label Feb 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conflicts/needs rebase Rebase to or merge with the latest base branch is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.