Code Monkey home page Code Monkey logo

Comments (7)

caglorithm avatar caglorithm commented on August 22, 2024 1

That's a remarkably weird bug

from neurolib.

caglorithm avatar caglorithm commented on August 22, 2024

What's the bug about?

from neurolib.

jajcayn avatar jajcayn commented on August 22, 2024

remember dpath library? it's the thing that allows searching in dict keys with star notation (e.g. *tau).. so when a numpy array which dtype is int is a value inside the dictionary, it fails... actually I guess that is the bug in the dpath library... however, it's very easy to overcome this by forcing all numpy arrays (so connectivity and delay matrices) to float (and they typically float)...

from neurolib.

caglorithm avatar caglorithm commented on August 22, 2024

when a numpy array which dtype is int is a value inside the dictionary, it fails... actually I guess that is the bug in the dpath library.

It seems weird that it depends on the value inside the array. Force-converting user-defined values is the most elegant solution but I guess it works until it doesn't :))

Can you post / reproduce the error?

from neurolib.

jajcayn avatar jajcayn commented on August 22, 2024

setup:

from dpath.util import search
import numpy as np

dct = {"aln.t.a": 12.0, "aln.t.b": 32., "aln.conn": np.array([[1, 1]])}
# first arg is to search where, second is what to search (using star notation), third is the separator in keys (dot by default)
list(search(dct, "*a", "."))

leads to:

AttributeError                            Traceback (most recent call last)
~/.virtualenvs/thalctx/lib/python3.7/site-packages/dpath/segments.py in kvs(node)
     13     try:
---> 14         return iter(node.items())
     15     except AttributeError:

AttributeError: 'numpy.int64' object has no attribute 'items'

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
<ipython-input-8-578683b23f73> in <module>
----> 1 list(search(dct, "*a", "."))

~/.virtualenvs/thalctx/lib/python3.7/site-packages/dpath/util.py in yielder()
    219     if yielded:
    220         def yielder():
--> 221             for segments, found in dpath.segments.walk(obj):
    222                 if keeper(segments, found):
    223                     yield (separator.join(map(dpath.segments.int_str, segments)), found)

~/.virtualenvs/thalctx/lib/python3.7/site-packages/dpath/segments.py in walk(obj, location)
     60             yield ((location + (k,)), v)
     61         for k, v in kvs(obj):
---> 62             for found in walk(v, location + (k,)):
     63                 yield found
     64

~/.virtualenvs/thalctx/lib/python3.7/site-packages/dpath/segments.py in walk(obj, location)
     60             yield ((location + (k,)), v)
     61         for k, v in kvs(obj):
---> 62             for found in walk(v, location + (k,)):
     63                 yield found
     64

~/.virtualenvs/thalctx/lib/python3.7/site-packages/dpath/segments.py in walk(obj, location)
     60             yield ((location + (k,)), v)
     61         for k, v in kvs(obj):
---> 62             for found in walk(v, location + (k,)):
     63                 yield found
     64

~/.virtualenvs/thalctx/lib/python3.7/site-packages/dpath/segments.py in walk(obj, location)
     46     '''
     47     if not leaf(obj):
---> 48         for k, v in kvs(obj):
     49             length = None
     50

~/.virtualenvs/thalctx/lib/python3.7/site-packages/dpath/segments.py in kvs(node)
     14         return iter(node.items())
     15     except AttributeError:
---> 16         return zip(range(len(node)), node)
     17
     18

TypeError: object of type 'numpy.int64' has no len()

however:

# note floats inside np.array
dct = {"aln.t.a": 12.0, "aln.t.b": 32., "aln.conn": np.array([[1.0, 1.0]])}
list(search(dct, "*a", "."))

leads to correct result

[('aln.t.a', 12.0)]

from neurolib.

jajcayn avatar jajcayn commented on August 22, 2024

one of the weirdest I ever encountered!

from neurolib.

jajcayn avatar jajcayn commented on August 22, 2024

it's deep inside dpath and relates to how dpath create segments (which is one of the building blocks of the whole machinery)

from neurolib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.