Skip to content

Commit

Permalink
Merge pull request #47 from boutproject/write-int32
Browse files Browse the repository at this point in the history
Ensure to always write int32
  • Loading branch information
ZedThree authored Apr 26, 2023
2 parents 2ae779e + c2e97a2 commit 618616b
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions boututils/datafile.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,8 +654,10 @@ def find_dim(dim):

# Write attributes, if present
try:
for attrname in data.attributes:
var.setncattr(attrname, data.attributes[attrname])
for attrname, attrval in data.attributes.items():
if isinstance(attrval, int):
attrval = np.int32(attrval)
var.setncattr(attrname, attrval)
except AttributeError:
pass

Expand Down Expand Up @@ -950,8 +952,7 @@ def write(self, name, data, info=False):
)

try:
for attrname in data.attributes:
attrval = data.attributes[attrname]
for attrname, attrval in data.attributes.items():
if type(attrval) == str:
attrval = attrval.encode(encoding="utf-8")
self.handle[name].attrs.create(attrname, attrval)
Expand Down

0 comments on commit 618616b

Please sign in to comment.