Skip to content

Commit 649417e

Browse files
authored
Merge pull request #432 from s22s/fix/431-rf-extract-bits-name-error
Fix rf_local_extract_bits argument parsing
2 parents d8ea781 + fa31210 commit 649417e

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

pyrasterframes/src/main/python/pyrasterframes/rasterfunctions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ def rf_local_extract_bits(tile, start_bit, num_bits=1):
522522
* `startBit` is the first bit to consider, working from the right. It is zero indexed.
523523
* `numBits` is the number of bits to take moving further to the left. """
524524
if isinstance(start_bit, int):
525-
start_bit = lit(bit_position)
525+
start_bit = lit(start_bit)
526526
if isinstance(num_bits, int):
527527
num_bits = lit(num_bits)
528528
return _apply_column_function('rf_local_extract_bits', tile, start_bit, num_bits)

pyrasterframes/src/main/python/tests/RasterFunctionsTests.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,16 @@ def test_mask(self):
348348
expected_data_values
349349
)
350350

351+
def test_extract_bits(self):
352+
one = np.ones((6, 6), 'uint8')
353+
t = Tile(84 * one)
354+
df = self.spark.createDataFrame([Row(t=t)])
355+
result_py_literals = df.select(rf_local_extract_bits('t', 2, 3)).first()[0]
356+
# expect value binary 84 => 1010100 => 101
357+
assert_equal(result_py_literals.cells, 5 * one)
358+
359+
result_cols = df.select(rf_local_extract_bits('t', lit(2), lit(3))).first()[0]
360+
assert_equal(result_cols.cells, 5 * one)
351361

352362
def test_resample(self):
353363
from pyspark.sql.functions import lit

0 commit comments

Comments
 (0)