Skip to content

Can't handle dicts containing numpy arrays #149

@donjan

Description

@donjan

dpath v2.0.1 (current pypi version) can't handle a dict with some numpy array further inside, even though I'm not dealing with the array directly.

Observed Behaviour

import numpy
import dpath.util

npa = numpy.array([42], dtype='uint64')
data = {'a': {'b': {'c': {'d': {'e': npa} }}}}
path = '/a/b/c'
dpath.util.get(data, path)

Yields:

[...]
  File "/[...]/venv-dev/lib/python3.8/site-packages/dpath/segments.py", line 48, in walk
    for k, v in kvs(obj):
  File "/[...]/venv-dev/lib/python3.8/site-packages/dpath/segments.py", line 16, in kvs
    return zip(range(len(node)), node)
TypeError: object of type 'numpy.uint64' has no len()

Expected Behaviour

Should yield:

 {'d': {'e': array([42], dtype=uint64)}}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions