Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions eccodes/highlevel/_bufr/coder.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,7 @@ def commit(self, entry) -> None:
codes_set(self._handle, f"#{rank}#{key}", value)
else:
if array.dtype.type == np.str_:
if array.size == 1: # [1]
codes_set(self._handle, key, array.data[0][0])
elif array.size > 1 and not np.any(array != array.data[0][0]):
if array.size > 1 and not np.any(array != array.data[0][0]):
codes_set_array(self._handle, key, array.data[0][0:1])
else:
codes_set_array(self._handle, key, array.data.ravel())
Expand Down Expand Up @@ -384,8 +382,6 @@ def commit(self, entry) -> None:
codes_release(self._clone_handle)
self._clone_handle = 0

# [1] This is a workaround for ECC-1623.
#
# [2] If all values in an array are the same, encode only a single scalar value.
#
# [3] The key 'centre' is also an alias for the header key 'headerCentre',
Expand Down
19 changes: 19 additions & 0 deletions tests/test_bufr_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,3 +332,22 @@ def test_data_assignment_with_non_native_types():
bufr["satelliteIdentifier"] = np.int16(0)
bufr["satelliteIdentifier"] = np.int32(0)
bufr["latitude"] = np.float32(0)


def test_data_set_string_uncompressed(): # ECC-2220
bufr = BUFRMessage("BUFR4")
bufr["unexpandedDescriptors"] = [1025]
bufr["stormIdentifier"] = "70A"
assert bufr["stormIdentifier"] == "70A"
bufr.pack()
assert bufr["stormIdentifier"] == "70A"


def test_data_set_string_compressed(): # ECC-2220
bufr = BUFRMessage("BUFR4")
bufr["compressedData"] = 1
bufr["unexpandedDescriptors"] = [1025]
bufr["stormIdentifier"] = "70A"
assert bufr["stormIdentifier"] == "70A"
bufr.pack()
assert bufr["stormIdentifier"] == "70A"
Loading