Skip to content

grass.pygrass: Fix Cats.delete(0) and CatsList.from_array - #8095

Draft
Mohit-Ak wants to merge 1 commit into
OSGeo:mainfrom
Mohit-Ak:fix/pygrass-cats-delete-zero
Draft

Mohit-Ak wants to merge 1 commit into
OSGeo:mainfrom
Mohit-Ak:fix/pygrass-cats-delete-zero

Conversation

@Mohit-Ak

Copy link
Copy Markdown

Description

Cats.delete() tested the category with if cat:, so delete(0) fell through to Vect_cat_del and removed every category of the layer; when category 0 was not present it still wiped the layer without raising. The check is now cat is not None.

CatsList.from_array() passed a Python list straight to Vect_array_to_cat_list, which raised ctypes.ArgumentError. It now builds a c_int array first.

Motivation and context

Category 0 is a valid category number, and from_array() had never worked (it was marked TODO: it's not working).

Fixes #8074

How has this been tested?

Added five tests to python/grass/pygrass/vector/tests/test_basic.py: delete(0) leaves the other categories, delete(0) on a layer without it raises ValueError and keeps the layer intact, delete(layer=1) still clears the layer, and from_array with a ranged list and with an empty list. Four of them fail on main and all pass with this change; the rest of test_basic.py (47 tests) and the module doctests pass. ruff/flake8 clean.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as before)

Checklist

  • PR title provides summary of the changes and starts with one of the pre-defined prefixes
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.

Cats.delete() checked the category with `if cat:`, so deleting category
0 removed every category of the layer instead. CatsList.from_array()
passed a Python list to Vect_array_to_cat_list and always raised
ctypes.ArgumentError.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libraries Python Related code is in Python tests Related to Test Suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] grass.pygrass: Cats.delete(0) deletes all layer categories instead of category 0

1 participant