Skip to content

Commit 2f204db

Browse files
authored
Merge pull request #139 from fact-project/h5py3
Fix string conversion for h5py >= 3
2 parents 65201e6 + 4f650cd commit 2f204db

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

fact/VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.26.1
1+
0.26.2

fact/io.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,9 @@ def read_h5py(
177177
dataset = group[col]
178178
array = to_native_byteorder(dataset[first:last])
179179

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

184184
if parse_dates and dataset.attrs.get('timeformat') is not None:
185185
array = pd.to_datetime(array, infer_datetime_format=True)

tests/test_io.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,8 @@ def test_read_data_h5py():
295295

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

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

0 commit comments

Comments
 (0)