Commits

Janez Demšar  committed 0d7efe8

- Value.__init__ now correctly constructs unknown values of type string
- Variable has new methods DC, DK and specialValue

  • Participants
  • Parent commits 95b9984

Comments (0)

Files changed (2)

File source/orange/cls_value.cpp

       return convertFromPython(obj1, val, var) ? Value_FromVariableValueType(type, var, val) : PYNULL;
     }
     else if (PyInt_Check(obj1) && PyInt_Check(obj2)) {
-      return Value_FromValueType(type, TValue((char)(int(PyInt_AsLong(obj1))), (signed char)PyInt_AsLong(obj2)));
+      int vartype = int(PyInt_AsLong(obj1));
+
+      if (vartype == STRINGVAR)
+        return Value_FromValueType(type, TValue(STRINGVAR, (signed char)PyInt_AsLong(obj2)));
+
+      if (vartype > TValue::FLOATVAR) {
+        PyErr_Format(PyExc_IndexError, "invalid value type (%i)", vartype);
+        return PYNULL;
+      }
+        
+      return Value_FromValueType(type, TValue((char)vartype, (signed char)PyInt_AsLong(obj2)));
     }
 
     PYERROR(PyExc_TypeError, "Value(): invalid arguments", PYNULL);

File source/orange/lib_kernel.cpp

 }
 
 
+PyObject *Variable_DC(PyObject *self) PYARGS(METH_NOARGS, "() -> DC")
+{
+  PyTRY
+    PVariable var = PyOrange_AsVariable(self);
+    return Value_FromVariableValue(var, var->DC());
+  PyCATCH
+}
+
+
+
+PyObject *Variable_DK(PyObject *self) PYARGS(METH_NOARGS, "() -> DK")
+{
+  PyTRY
+    PVariable var = PyOrange_AsVariable(self);
+    return Value_FromVariableValue(var, var->DK());
+  PyCATCH
+}
+
+
+PyObject *Variable_specialValue(PyObject *self, PyObject *arg) PYARGS(METH_O, "(int) -> special value")
+{
+  PyTRY
+    int valType;
+    if (!convertFromPython(arg, valType))
+      return PYNULL;
+    PVariable var = PyOrange_AsVariable(self);
+    return Value_FromVariableValue(var, var->specialValue(valType));
+  PyCATCH
+}
+
+
+
 PyObject *EnumVariable_getitem_sq(PyObject *self, int index)
 { PyTRY
     CAST_TO(TEnumVariable, var)