Skip to content

Conversation

@calgray
Copy link

@calgray calgray commented Sep 18, 2023

JMESPath.py is limited in that only the dict and list derived containers returned by the built-in json library are supported in the object hierarchy due to the use of isinstance. A very notable arraylike instance that does not derive directly from these containers is a numpy.ndarray which can be deserialized using the JSON-like msgpack library with msgpack_numpy.

This changeset aims to add support for arraylike (list, tuple and numpy.ndarray) containers in place of parsed JSON arrays and without adding any dependency on the numpy library. This is done using the documented numpy array interface protocol of which many more arraylike libraries adhere to such as xarray, dask, astropy and cupy.

(pandas.Series is also arraylike but limited to 1D as multidimensional Series isn't an intended use case and has slicing issues)

@calgray calgray changed the title Add support 'arraylike' objects as JSON arrays Add support for 'arraylike' objects as JSON arrays Sep 18, 2023
@calgray calgray marked this pull request as ready for review September 18, 2023 04:44
@@ -1,5 +1,6 @@
import math
import json
from typing import Sequence
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is deprecated and should be

Suggested change
from typing import Sequence
from collections.abc import Sequence

I think

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's only available in Python 3.9+ but the project still declares support for 3.7 and 3.8

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's available in older versions. only subscripting like Sequence[int] (which is not used) is only available in newer versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants