Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed how character strings are stripped and encoded
  • Loading branch information
daminton committed Sep 4, 2021
1 parent df7a719 commit 9349bf3
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions python/swiftest/swiftest/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,9 @@ def swiftest2xr(param):

return ds

def xstrip(a):
func = lambda x: np.char.strip(x)
return xr.apply_ufunc(func, a.str.decode(encoding='utf-8'))

def clean_string_values(param, ds):
"""
Expand All @@ -719,13 +722,13 @@ def clean_string_values(param, ds):
ds : xarray dataset with the strings cleaned up
"""
if 'name' in ds:
ds['name'] = ds['name'].str.decode(encoding='utf-8')
ds['name'] = xstrip(ds['name'])
if 'particle_type' in ds:
ds['particle_type'] = ds['particle_type'].str.decode(encoding='utf-8')
ds['particle_type'] = xstrip(ds['particle_type'])
if 'status' in ds:
ds['status'] = ds['status'].str.decode(encoding='utf-8')
ds['status'] = xstrip(ds['status'])
if 'origin_type' in ds:
ds['origin_type'] = ds['origin_type'].str.decode(encoding='utf-8')
ds['origin_type'] = xstrip(ds['origin_type'])
return ds


Expand Down

0 comments on commit 9349bf3

Please sign in to comment.