Skip to content

Commit

Permalink
Coerce types for factor codes before placeholder substitution.
Browse files Browse the repository at this point in the history
This avoids any attempt to insert -1 into an unsigned NumPy array,
which triggers a NumPy warning in any case.
  • Loading branch information
LTLA committed Jan 22, 2024
1 parent ade6eeb commit a256d04
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/dolomite_base/_utils_factor.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ def save_factor_to_hdf5(handle: h5py.Group, f: Factor):
def load_factor_from_hdf5(handle: h5py.Group):
chandle = handle["codes"]
codes = chandle[:]
codes = codes.astype(numpy.int32, copy=False)

if "missing-value-placeholder" in chandle.attrs:
placeholder = chandle.attrs["missing-value-placeholder"]
codes[codes == placeholder] = -1
Expand All @@ -35,6 +37,5 @@ def load_factor_from_hdf5(handle: h5py.Group):
if "ordered" in handle.attrs:
ordered = handle.attrs["ordered"][()] != 0

codes = codes.astype(numpy.int32, copy=False)
levels = strings.load_string_vector_from_hdf5(handle["levels"])
return Factor(codes, levels, ordered = ordered)

0 comments on commit a256d04

Please sign in to comment.