11# A dtype that stores pointers to strings
22
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.
78
89## Building
910
1011Ensure Meson and NumPy are installed in the python environment you would like to use:
1112
1213```
13- $ python3 -m pip install meson meson-python build patchelf
14+ $ python3 -m pip install meson meson-python
1415```
1516
1617It 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:
2021$ pip install -i https://pypi.anaconda.org/scientific-python-nightly-wheels/simple numpy
2122```
2223
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.
2433
2534``` bash
2635$ rm -r dist/
2736$ meson build
2837$ python -m build --wheel -Cbuilddir=build
38+ $ python -m pip install dist/path-to-wheel-file.whl
2939```
3040
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:
3245
3346``` 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())
3555```
0 commit comments