File: test-ascii-length-bug.py

package info (click to toggle)
r-cran-hdf5r 1.3.8%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 10,192 kB
  • sloc: ansic: 76,883; sh: 82; python: 32; makefile: 13
file content (21 lines) | stat: -rw-r--r-- 728 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import random, string
import numpy as np
import h5py

def random_string(n=10):
    return ''.join(random.SystemRandom().choice(string.digits + string.ascii_uppercase) 
                   for _ in range(n))

fn = "test-ascii-length-bug.h5"


test = h5py.File(fn, "w")
standard_ascii = "mar231-21y ha131d a litt321le lamb its Fleece As Wh31ite as snow".split()
random_strings = [random_string() for _ in range(20)]
codedb = np.array(standard_ascii, dtype="a10")
test.create_dataset("/test/ascii", data=codedb)
codedc = np.array(random_strings, dtype="a11")
test.create_dataset("/test/randomalpha", data=codedc)
codedd = np.array(random_strings, dtype="a10")
test.create_dataset("/test/randomalphashort", data=codedd)
test.close()