Skip to content

Commit ba0eeda

Browse files
committed
test(python): RS_SetBandNoDataValue null value clears the band's nodata
1 parent 38edff1 commit ba0eeda

2 files changed

Lines changed: 22 additions & 10 deletions

File tree

docs/reference/sql/rs_setbandnodatavalue.qmd

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,19 @@
1919
title: RS_SetBandNoDataValue
2020
description: >
2121
Sets the nodata value of the specified band, packing the value into the band's
22-
native data type. A null raster, band, or nodata value yields a null raster.
23-
This is metadata-only: raster cell values are not modified.
22+
native data type. A null raster or band yields a null raster; a null nodata
23+
value instead clears the addressed band's nodata. This is metadata-only:
24+
raster cell values are not modified.
2425
kernels:
2526
- returns: raster
2627
args:
2728
- raster
2829
- name: nodata
2930
type: float64
3031
description: >
31-
Nodata value to set. The raster must be single-band; for a multiband
32-
raster, specify the band with the three-argument form below.
32+
Nodata value to set, or null to clear the band's nodata. The raster must
33+
be single-band; for a multiband raster, specify the band with the
34+
three-argument form below.
3335
- returns: raster
3436
args:
3537
- raster
@@ -38,7 +40,7 @@ kernels:
3840
description: Band index (1-based).
3941
- name: nodata
4042
type: float64
41-
description: Nodata value to set on the band.
43+
description: Nodata value to set on the band, or null to clear it.
4244
---
4345

4446
## Examples
@@ -50,3 +52,9 @@ SELECT RS_BandNoDataValue(RS_SetBandNoDataValue(RS_Example(), 1, 0), 1);
5052
```sql
5153
SELECT RS_BandNoDataValue(RS_SetBandNoDataValue(RS_Example(), 2, 255), 2);
5254
```
55+
56+
A null nodata value clears the band's existing nodata, so the getter reads back null:
57+
58+
```sql
59+
SELECT RS_BandNoDataValue(RS_SetBandNoDataValue(RS_Example(), 1, CAST(NULL AS DOUBLE)), 1);
60+
```

python/sedonadb/tests/functions/test_raster_functions.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,10 @@ def test_rs_setgeoreference_esri_skewed_roundtrips():
278278
# Three-arg form targets a specific band; read it back with the getter.
279279
("RS_BandNoDataValue(RS_SetBandNoDataValue(RS_Example(), 1, 0), 1)", 0.0),
280280
("RS_BandNoDataValue(RS_SetBandNoDataValue(RS_Example(), 2, 255), 2)", 255.0),
281-
# A null nodata value yields a null raster, so the getter returns null.
281+
# A null nodata value clears the addressed band's nodata (band 1 starts
282+
# at 127), so the getter then reads back null for that band.
282283
(
283-
"RS_BandNoDataValue(RS_SetBandNoDataValue(RS_Example(), CAST(NULL AS DOUBLE)), 1)",
284+
"RS_BandNoDataValue(RS_SetBandNoDataValue(RS_Example(), 1, CAST(NULL AS DOUBLE)), 1)",
284285
None,
285286
),
286287
],
@@ -289,12 +290,15 @@ def test_rs_setbandnodatavalue(expr, expected):
289290
SedonaDB().assert_query_result(f"SELECT {expr}", expected)
290291

291292

292-
def test_rs_setbandnodatavalue_two_arg_requires_single_band():
293+
@pytest.mark.parametrize("value", ["0", "CAST(NULL AS DOUBLE)"])
294+
def test_rs_setbandnodatavalue_two_arg_requires_single_band(value):
293295
# The 2-arg form is ambiguous on a multiband raster (RS_Example has multiple
294-
# bands), so it errors rather than silently setting only band 1.
296+
# bands), so it errors rather than silently setting only band 1. A null value
297+
# clears the band's nodata rather than short-circuiting to a null raster, so
298+
# it hits the same ambiguity and errors too.
295299
with pytest.raises(Exception, match="specify which band"):
296300
SedonaDB().assert_query_result(
297-
"SELECT RS_SetBandNoDataValue(RS_Example(), 0)", None
301+
f"SELECT RS_SetBandNoDataValue(RS_Example(), {value})", None
298302
)
299303

300304

0 commit comments

Comments
 (0)