Skip to content

Commit

Permalink
fix CI tests and int(infinity) bug
Browse files Browse the repository at this point in the history
  • Loading branch information
honzaflash committed Dec 3, 2024
1 parent f0e9b12 commit 1853189
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
6 changes: 5 additions & 1 deletion bufrtools/encoding/bufr.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
import io
import os
import math
import sys

import numpy as np
from bufrtools.util.parse import parse_ref
from bufrtools.util.bitmath import shift_uint, encode_uint


INT_INFINITY = sys.maxsize


def encode_bufr(message: dict, context: dict):
"""Encodes a BUFR file based on the contents of message."""
if 'buf' not in context:
Expand Down Expand Up @@ -167,7 +171,7 @@ def encode_section4(message: dict, context: dict):
if seq['offset']:
value = value - seq['offset']
# The value should be ROUNDED to the nearest integer
value = int(np.round(value))
value = int(min(np.round(value), INT_INFINITY))
write_uint(write_buf, value, bit_offset, bitlen)
bit_offset += seq['bit_len']
elif seq['type'] == 'string':
Expand Down
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ dependencies:
- cftime
- pyyaml
- pandas
- numpy
- pocean-core>=1.9.3
- pyarrow
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
cftime
numpy
pandas
pocean-core>=1.9.3
pyarrow
Expand Down

0 comments on commit 1853189

Please sign in to comment.