Skip to content

Updates to match the NEP #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions stringdtype/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
# A dtype that stores pointers to strings

This is a simple proof-of-concept dtype using the (as of early 2023) experimental
[new dtype
implementation](https://numpy.org/neps/nep-0041-improved-dtype-support.html) in
NumPy.
This is the prototype implementation of the variable-width UTF-8 string DType
described in [NEP 55](https://numpy.org/neps/nep-0055-string_dtype.html).

See the NEP for implementation details and usage examples. Full
documentation will be written as before this code is merged into NumPy.

## Building

Ensure Meson and NumPy are installed in the python environment you would like to use:

```
$ python3 -m pip install meson meson-python build patchelf
$ python3 -m pip install meson meson-python
```

It is important to have the latest development version of numpy installed.
Expand All @@ -20,16 +21,35 @@ Nightly wheels work well for this purpose, and can be installed easily:
$ pip install -i https://pypi.anaconda.org/scientific-python-nightly-wheels/simple numpy
```

Build with meson, create a wheel, and install it.
You can install with `pip` directly, taking care to disable build isolation so
the numpy nightly gets picked up at build time:

```bash
$ pip install -v . --no-build-isolation
```

If you want to work on the `stringdtype` code, you can build with meson,
create a wheel, and install it.

```bash
$ rm -r dist/
$ meson build
$ python -m build --wheel -Cbuilddir=build
$ python -m pip install dist/path-to-wheel-file.whl
```

Or simply install directly, taking care to install without build isolation:
## Usage

The dtype will not import unless you run python executable with
the `NUMPY_EXPERIMENTAL_DTYPE_API` environment variable set:

```bash
$ pip install -v . --no-build-isolation
$ NUMPY_EXPERIMENTAL_DTYPE_API=1 python
Python 3.11.3 (main, May 2 2023, 11:36:22) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from stringdtype import StringDType
>>> import numpy as np
>>> arr = np.array(["hello", "world"], dtype=StringDType())
>>> arr
array(['hello', 'world'], dtype=StringDType())
```
544 changes: 260 additions & 284 deletions stringdtype/stringdtype/src/casts.c

Large diffs are not rendered by default.

Loading