# Python Dataset Error

**URL:** <https://forum.inductiveautomation.com/t/python-dataset-error/93463>\
**Category:** Ignition\
**Created:** [July 19, 2024, 1:37pm UTC](https://forum.inductiveautomation.com/t/python-dataset-error/93463 "2024-07-19T13:37:15Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rick\_Pietruszka](https://avatars.discourse-cdn.com/v4/letter/r/b5a626/32.png) [@Rick\_Pietruszka](https://forum.inductiveautomation.com/u/Rick_Pietruszka)\
**Post date:** [July 19, 2024, 1:37pm UTC](https://forum.inductiveautomation.com/t/python-dataset-error/93463/1 "2024-07-19T13:37:15Z")

</div>

Since I am not a career programmer, but a controls guy, I am using some code I found in the forums here to manipulate an excel spreadsheet using the apache poi. At this point of the code I am getting an error:

# Create header row in the sheet

```
	headerRow = sheet.createRow(0)
	for i, col in enumerate(pyDS.getColumnNames()):

```

pyDS is the python dataset. The error I am getting is:

AttributeError: 'com.inductiveautomation.ignition.common.script.bui' object has no attribute 'getColumnName'

Any help is appreciated.

Thanks!

RP

---

<div class="post-metadata">

**Author:** ![drojas](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drojas/32/3403_2.png) [@drojas](https://forum.inductiveautomation.com/u/drojas)\
**Post date:** [July 19, 2024, 2:05pm UTC](https://forum.inductiveautomation.com/t/python-dataset-error/93463/2 "2024-07-19T14:05:52Z")

</div>

Are you sure pyDS is not None?

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [July 19, 2024, 2:12pm UTC](https://forum.inductiveautomation.com/t/python-dataset-error/93463/3 "2024-07-19T14:12:50Z")

</div>

The error you show doesn't match the code you posted.  
See how you're calling `getColumnNames`, but the error says `getColumnName` ?  
Is that a typo, or is there some other place you're trying to call `getColumnName`, which, in fact, doesn't exist ?

---

<div class="post-metadata">

**Author:** ![Rick\_Pietruszka](https://avatars.discourse-cdn.com/v4/letter/r/b5a626/32.png) [@Rick\_Pietruszka](https://forum.inductiveautomation.com/u/Rick_Pietruszka)\
**Post date:** [July 19, 2024, 2:22pm UTC](https://forum.inductiveautomation.com/t/python-dataset-error/93463/4 "2024-07-19T14:22:53Z")

</div>

Oops, sorry about that. It is in fact getColumnNames. I had tried it without the s on the end as I had seen somewhere else that had a method like that.

---

<div class="post-metadata">

**Author:** ![Rick\_Pietruszka](https://avatars.discourse-cdn.com/v4/letter/r/b5a626/32.png) [@Rick\_Pietruszka](https://forum.inductiveautomation.com/u/Rick_Pietruszka)\
**Post date:** [July 19, 2024, 2:24pm UTC](https://forum.inductiveautomation.com/t/python-dataset-error/93463/5 "2024-07-19T14:24:10Z")

</div>

I am sure. To test this all I am doing is making a simple dataset:  
headers = ["Letters", "Numbers"]  
data=  
data.append(['A',1])  
data.append(['B',2])  
data.append(['C',3])  
dataOut = system.dataset.toDataSet(headers, data)

pythonDataset = system.dataset.toPyDataSet(dataOut)

EXCEL.WRITEXLSX.listToExcel(pythonDataset)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 19, 2024, 2:52pm UTC](https://forum.inductiveautomation.com/t/python-dataset-error/93463/6 "2024-07-19T14:52:09Z")

</div>

How old is your Ignition version?

In older Ignition, `.getColumnNames()` (aka `.columnNames`) is available only on proper `Dataset` instances, not on `PyDataset` instances.

---

<div class="post-metadata">

**Author:** ![Rick\_Pietruszka](https://avatars.discourse-cdn.com/v4/letter/r/b5a626/32.png) [@Rick\_Pietruszka](https://forum.inductiveautomation.com/u/Rick_Pietruszka)\
**Post date:** [July 19, 2024, 3:10pm UTC](https://forum.inductiveautomation.com/t/python-dataset-error/93463/7 "2024-07-19T15:10:02Z")

</div>

Ignition Platform

8.1.36 (b2024010211)

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [July 19, 2024, 3:16pm UTC](https://forum.inductiveautomation.com/t/python-dataset-error/93463/8 "2024-07-19T15:16:33Z")

</div>

Okay, let's take a step back.

Post:

1. Exactly the error message you are getting, with the **full** details/stacktrace attached.
2. Exactly the code you're running in the script console/on your button/whatever.
3. Exactly the code you've got in the project library, apparently under the `EXCEL` package.

Post all of those here as [preformatted text](https://forum.inductiveautomation.com/t/wiki-how-to-post-code-on-this-forum/77831), so that indentation information (_crucial_ to Python) is not lost.

Until you do that, we're all just taking stabs in the dark trying to help you.

---

<div class="post-metadata">

**Author:** ![drojas](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drojas/32/3403_2.png) [@drojas](https://forum.inductiveautomation.com/u/drojas)\
**Post date:** [July 19, 2024, 3:27pm UTC](https://forum.inductiveautomation.com/t/python-dataset-error/93463/9 "2024-07-19T15:27:04Z")

</div>

@Rick_Pietruszka , I just tried your script. Here is what happened:

Calling .getColumnNames() within the enumerate() function returns either a 'com.inductiveautomation.ignition.common.script.bui' error if it is a PyDataSet or 'com.inductiveautomation.ignition.common.BasicDatas' error if it is a DataSet.

However, simply saving the column names to another variable, then using that in your enumerate function works like a champ

```python
columnNames = pyDS.getColumnNames()
for i, col in enumerate(columnNames):

```

---

<div class="post-metadata">

**Author:** ![Rick\_Pietruszka](https://avatars.discourse-cdn.com/v4/letter/r/b5a626/32.png) [@Rick\_Pietruszka](https://forum.inductiveautomation.com/u/Rick_Pietruszka)\
**Post date:** [July 19, 2024, 3:44pm UTC](https://forum.inductiveautomation.com/t/python-dataset-error/93463/10 "2024-07-19T15:44:13Z")

</div>

It sounded like a winning solution, but it gave the same error on the columnNames = pyDS.getColumnNames()

---

<div class="post-metadata">

**Author:** ![Rick\_Pietruszka](https://avatars.discourse-cdn.com/v4/letter/r/b5a626/32.png) [@Rick\_Pietruszka](https://forum.inductiveautomation.com/u/Rick_Pietruszka)\
**Post date:** [July 19, 2024, 3:54pm UTC](https://forum.inductiveautomation.com/t/python-dataset-error/93463/11 "2024-07-19T15:54:28Z")

</div>

I got the code to work by simply not converting the dataset to a python dataset earlier in the script. I commented out the code for system.dataset.toPyDataSet(dsIn) and it is working great now. So ignition is not liking the methods for handling python datasets.

---

<div class="post-metadata">

**Author:** ![drojas](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drojas/32/3403_2.png) [@drojas](https://forum.inductiveautomation.com/u/drojas)\
**Post date:** [July 19, 2024, 3:57pm UTC](https://forum.inductiveautomation.com/t/python-dataset-error/93463/12 "2024-07-19T15:57:20Z")

</div>

@Rick_Pietruszka , using the simple dataset example, the .getColumNames() function works on both a dataset and pyDataset. If it isn't working for you, perhaps there is something wrong with the pyDataset itself

```python
headers = ["Name","Value"]
data = []
data.append(['A',1])
data.append(['B',2])
data.append(['C',3])

ds = system.dataset.toDataSet(headers, data)
pyDS = system.dataset.toPyDataSet(ds)

columnNames = ds.getColumnNames()
pyColumnNames = pyDS.getColumnNames()

print columnNames
print pyColumnNames

for i, col in enumerate(pyColumnNames): #works fine
	print col
	
#for i, col in enumerate(ds.getColumnnames()): #gives error
#	print col
#for i, col in enumerate(pyDS.getColumnnames()): #gives error
#	print col

```

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [July 19, 2024, 3:59pm UTC](https://forum.inductiveautomation.com/t/python-dataset-error/93463/13 "2024-07-19T15:59:04Z")

</div>

I generally cast it to a list to prevent other issues that can arise from using the object directly:

```python
columnNames = list(pyDS.getColumnNames())

```

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [July 19, 2024, 4:42pm UTC](https://forum.inductiveautomation.com/t/python-dataset-error/93463/14 "2024-07-19T16:42:18Z")

</div>

It never made sense to me that you can't use the list of headers you just extracted from a dataset to create another dataset without casting it first...

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 19, 2024, 4:59pm UTC](https://forum.inductiveautomation.com/t/python-dataset-error/93463/15 "2024-07-19T16:59:25Z")

</div>

It's because Ignition's `toDataSet()` function is strictly checking for python's list, where it should be looking any duck-typed list-like object. Java's `java.util.List<>` interface is wrapped by jython in a list-like implementation.

Arguably a poor API choice on IA's part, _ **many** _ years ago.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [July 19, 2024, 5:05pm UTC](https://forum.inductiveautomation.com/t/python-dataset-error/93463/16 "2024-07-19T17:05:40Z")

</div>

Oh, I won't argue it, I'd say it's _unambiguously_ a poor choice. We're explicitly checking for `PySequence`, and have been since, as far as I can tell, we migrated VCS systems to Git in _2011_.

Maybe I'll sneak in a fix for 8.3...
