Orange Forum • View topic - Type checking in Orange.data.Table constructor

Type checking in Orange.data.Table constructor

A place to ask questions about methods in Orange and how they are used and other general support.

Type checking in Orange.data.Table constructor

Postby whoeverest » Fri Jun 22, 2012 16:39

Today, while writing some code that creates an Orange Table, I came into the following situation: I tried to pass a list of tuples as instances for the Table and got an error: "invalid argument type (expected list, got 'tuple')".

I fixed the problem and converted the tuple to a list, but I was wondering: what is the purpose of this check? From what I know, the pythonic way would be to try and iterate the received object and if that fails, then return an error. To me, in this case, type checking looks unnecessary, but I may be missing a constraint in another part of Orange.

This is the function in question, extracted from /source/orange/cls_example.cpp:

Code: Select all
if (!PyList_Check(lst)) {
    PyErr_Format(PyExc_TypeError,
                 "invalid argument type (expected list, got '%s)",
                 lst ? lst->ob_type->tp_name : "None");
    return false;
  }

Re: Type checking in Orange.data.Table constructor

Postby Janez » Tue Jun 26, 2012 21:56

You're right: the function should accept any sequence. On the other hand, you're also right that this constraint could be needed for another part of Orange, so I wouldn't dare to change it. If this looks as a sign of lousy planning and documenting, it's because this is a sign of lousy planning and documenting.

This is one of the reasons why Orange 3.0 is being mostly reimplemented from scratch (but maintaining compatibility except for things that are really awkward and non-Pythonic).

(Coincidentally, when I was writing this reply vlc decided to play the soundtrack of Before the Rain. What a great music and movie! I worry though that vlc may be smarter than we think.)

Re: Type checking in Orange.data.Table constructor

Postby whoeverest » Sun Jul 01, 2012 15:40

:)))) It looks like VLC became nationality-aware. I'm also a fan of Anastasia. The "Before the Rain" soundtrack is unbelievably good and I think you should also check out the album "Nocturnal", in case you haven't. I was blown away when I first heard it, it's a genius piece of music.

Now back on the topic: thank you for investigating. Before I wrote this post, I consulted with a few of my programmer friends and we all agreed it didn't look right. So it's good to know we were on the right track.


Return to Questions & Support