So I’m not very familiar with Jython and how I can do certain things, hence the probably basic question.
I want to ensure that the parameter being passed to a function is either a Dataset or a PyDataSet, but checking the type of a Dataset returns <type 'com.inductiveautomation.ignition.common.BasicDataset'> and I can’t seem to find a way to actually compare the type of a variable to this. isinstance(dataset, com.inductiveautomation.ignition.common.BasicDataset) just gives an error: “name ‘com’ is not defined”.
Is there something simple I’m missing?
             
            
              
              
              
            
            
           
          
            
            
              from com.inductiveautomation.ignition.common import BasicDataset
ds = system.dataset.toDataSet(["columnOne", "columnTwo"], [[1, 2]])
print isinstance(ds, BasicDataset)
             
            
              
              
              2 Likes
            
            
           
          
            
            
              I don’t know what your intentions are, but if you want to accept any dataset type you should compare against com.inductiveautomation.ignition.common.Dataset.
             
            
              
              
              
            
            
           
          
            
            
              Does that include PyDatasets?
I basically just want to do this:
- If it’s a PyDataset, pass it along as is to the rest of the function.
- If it’s a dataset that can be converted to a PyDataset, convert it first.
 
            
              
              
              
            
            
           
          
            
            
              PyDataSet does implement Dataset, you’ll just need 2 checks.
3 possibilities:
- not a Dataset at all
- a Dataset, but not a PyDataSet
- a PyDataSet
 
            
              
              
              1 Like
            
            
           
          
            
            
              Sorry to keep adding on questions, but how do I check for if it’s a PyDataSet? The type of a PyDataSet appears to be <type 'com.inductiveautomation.ignition.common.script.builtin.DatasetUtilities$PyDataSet'> which raises syntax errors when I try to compare against it because of that $.
             
            
              
              
              
            
            
           
          
            
            
              Hmm. I don’t know offhand… try replacing the “$” with a “.”:
from com.inductiveautomation.ignition.common.script.builtin import DatasetUtilities
isinstance(ds, DatasetUtilities.PyDataSet)
             
            
              
              
              1 Like
            
            
           
          
            
            
              Seems like that did the trick!
             
            
              
              
              
            
            
           
          
            
            
              I wonder if toPyDataSet should just be smart enough to do no work if passed a PyDataSet and simply return it.
(it’s not, pondering a future change though)
             
            
              
              
              
            
            
           
          
            
            
              It seems to work for me?
pySet = system.dataset.toPyDataSet(ds)
pypyset = system.dataset.toPyDataSet(pySet)
isinstance(pySet, DatasetUtilities.PyDataSet) #=> True
isinstance(pypyset, DatasetUtilities.PyDataSet) #=> True
And I don’t get any errors.
             
            
              
              
              
            
            
           
          
            
            
              Yeah it should work it’s just not as efficient as it could be.
             
            
              
              
              1 Like
            
            
           
          
            
            
              Alright cool, thanks!
I’ll just check if it’s a Dataset and then run toPyDataset regardless and that’ll be it. Thanks again!
             
            
              
              
              1 Like
            
            
           
          
            
            
              Hi
Do you have a solution for type BasicStreamingDataset ?
             
            
              
              
              
            
            
           
          
            
            
              Hi,
Do you have the solution for objects (org.python.core.PyUnicode) ?
             
            
              
              
              1 Like