1
1
# A dtype that stores pointers to strings
2
2
3
- This is a simple proof-of-concept dtype using the (as of early 2023) experimental
4
- [ new dtype
5
- implementation] ( https://numpy.org/neps/nep-0041-improved-dtype-support.html ) in
6
- NumPy.
3
+ This is the prototype implementation of the variable-width UTF-8 string DType
4
+ described in [ NEP 55] ( https://numpy.org/neps/nep-0055-string_dtype.html ) .
5
+
6
+ See the NEP for implementation details and usage examples. Full
7
+ documentation will be written as before this code is merged into NumPy.
7
8
8
9
## Building
9
10
10
11
Ensure Meson and NumPy are installed in the python environment you would like to use:
11
12
12
13
```
13
- $ python3 -m pip install meson meson-python build patchelf
14
+ $ python3 -m pip install meson meson-python
14
15
```
15
16
16
17
It is important to have the latest development version of numpy installed.
@@ -20,16 +21,35 @@ Nightly wheels work well for this purpose, and can be installed easily:
20
21
$ pip install -i https://pypi.anaconda.org/scientific-python-nightly-wheels/simple numpy
21
22
```
22
23
23
- Build with meson, create a wheel, and install it.
24
+ You can install with ` pip ` directly, taking care to disable build isolation so
25
+ the numpy nightly gets picked up at build time:
26
+
27
+ ``` bash
28
+ $ pip install -v . --no-build-isolation
29
+ ```
30
+
31
+ If you want to work on the ` stringdtype ` code, you can build with meson,
32
+ create a wheel, and install it.
24
33
25
34
``` bash
26
35
$ rm -r dist/
27
36
$ meson build
28
37
$ python -m build --wheel -Cbuilddir=build
38
+ $ python -m pip install dist/path-to-wheel-file.whl
29
39
```
30
40
31
- Or simply install directly, taking care to install without build isolation:
41
+ ## Usage
42
+
43
+ The dtype will not import unless you run python executable with
44
+ the ` NUMPY_EXPERIMENTAL_DTYPE_API ` environment variable set:
32
45
33
46
``` bash
34
- $ pip install -v . --no-build-isolation
47
+ $ NUMPY_EXPERIMENTAL_DTYPE_API=1 python
48
+ Python 3.11.3 (main, May 2 2023, 11:36:22) [GCC 11.3.0] on linux
49
+ Type " help" , " copyright" , " credits" or " license" for more information.
50
+ >>> from stringdtype import StringDType
51
+ >>> import numpy as np
52
+ >>> arr = np.array([" hello" , " world" ], dtype=StringDType())
53
+ >>> arr
54
+ array([' hello' , ' world' ], dtype=StringDType())
35
55
```
0 commit comments