Skip to content

Commit

Permalink
Merge pull request #139 from fact-project/h5py3
Browse files Browse the repository at this point in the history
Fix string conversion for h5py >= 3
  • Loading branch information
maxnoe authored Apr 7, 2021
2 parents 65201e6 + 4f650cd commit 2f204db
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion fact/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.26.1
0.26.2
6 changes: 3 additions & 3 deletions fact/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ def read_h5py(
dataset = group[col]
array = to_native_byteorder(dataset[first:last])

# pandas cannot handle bytes, convert to str
if array.dtype.kind == 'S':
array = array.astype(str)
# decode unicode strings to str
if array.dtype.kind in {'S', 'O'}:
array = array.astype('U')

if parse_dates and dataset.attrs.get('timeformat') is not None:
array = pd.to_datetime(array, infer_datetime_format=True)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,8 @@ def test_read_data_h5py():

df = pd.DataFrame({
'x': np.random.normal(size=50).astype('float32'),
'N': np.random.randint(0, 10, dtype='uint8', size=50)
'N': np.random.randint(0, 10, dtype='uint8', size=50),
'name': [f"s{i}" for i in range(50)],
}).sort_index(1)

with tempfile.NamedTemporaryFile(suffix='.hdf5') as f:
Expand Down

0 comments on commit 2f204db

Please sign in to comment.