Skip to content

NamedTuple #213

Closed
Closed
@philippeller

Description

@philippeller

I cannot convert a python namedtuple to a julia NamedTuple. Here a minimal example:

from juliacall import Main as jl
from collections import namedtuple

t = namedtuple('test', 'a b')
x = t(a=1, b=2)
jl.convert(jl.NamedTuple, x)

which results in the Error:

TypeError                                 Traceback (most recent call last)
<ipython-input-245-c2a0b5ab7412> in <module>
      3 x = t(a=1, b=2)
      4 
----> 5 jl.convert(jl.NamedTuple, x)

~/anaconda3/lib/python3.8/site-packages/juliacall/__init__.py in __call__(self, *args, **kwargs)
    199             return ValueBase.__dir__(self) + self._jl_callmethod($(pyjl_methodnum(pyjlany_dir)))
    200         def __call__(self, *args, **kwargs):
--> 201             return self._jl_callmethod($(pyjl_methodnum(pyjlany_call)), args, kwargs)
    202         def __len__(self):
    203             return self._jl_callmethod($(pyjl_methodnum(pyjlany_op(length))))

TypeError: Julia: MethodError: Cannot `convert` an object of type 
  Tuple{Int64, Int64} to an object of type 
  NamedTuple
Closest candidates are:
  convert(::Type{NamedTuple}, !Matched::ShapedAsNT) at /home/peller/.julia/packages/ValueShapes/03j48/src/named_tuple_shape.jl:362
  convert(::Type{T}, !Matched::T) where T at essentials.jl:205
  NamedTuple(::Any) at namedtuple.jl:107```

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