Error when calling RowLabelArray()

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Error when calling RowLabelArray()

la volta statistics

Dear All

 

I have several thousand tables in about hundred different output files saved. I written some code to open this files and do some manipulation on the tables.

However, when I call for RowLabelArray [rowlabels = PivotTable.RowLabelArray()]

I get from time to time (at least once in ten) the following error.

 

Traceback (most recent call last):

  File "<string>", line 23, in <module>

_SpssClient.SpssClientException: (16619, 'An error occured in the Pivot Table.', 'com.spss.vis.exception.VisualizationInternalException: An internal error occured')

 

You may reproduce the error by calling the Python code below (Python code 1) several times in a row. I noticed that the error gets less frequent, when I introduce a timer [time.sleep(0.5)] directly before the call for the RowLabelArray. But this would increase the formatting time for more than an hour with the amount of tables I want to format.

 

Interestingly, this error never occurs, when I run the same code without opening and saving the output files (sees Python code 2).

 

 

I use SPSS 18.02 on a Windows XP system.

 

Can someone help me?

 

TIA, Christian

 

 

 

* Code for illustrating the Error.

**********************************.

New file.

DATASET Close All.

 

data list list

/Medi(F8.0) Sex(F8.1) Age(F8.2) .

begin data

1 1 44.25

2 1 52.92

1 1 37.21

1 1 60.87

2 1 58.69

2 2 43.17

1 2 44.93

1 1 34.19

1 2 39.96

2 1 63.04

End Data.

 

Var Label Medi 'Treatment'.

Val Label Medi 1 'Verum'

               2 'Placebo'.

 

Var Label Sex "Gender".

Val Label Sex 1 "male"

              2 "female".

 

Compute Pat = 1.

Var Label Pat "Total".

VaL Label Pat 1 " ".

 

 

CTABLES

/FORMAT EMPTY = " "

/VLABELS VARIABLES=Medi sex Age DISPLAY=DEFAULT

/TABLE Pat [c] [Count " " F8.0] +

sex [C] [COUNT "N" F8.0, COLPCT.COUNT "%" PCT8.1]

BY Medi [c]

/Titles TITLE = "My Table 2"

/SLABELS POSITION=ROW

/CATEGORIES VARIABLES = Medi ORDER=A KEY=VALUE EMPTY=INCLUDE TOTAL=YES POSITION=AFTER

/CATEGORIES VARIABLES=sex ORDER=A KEY=VALUE EMPTY=INCLUDE.

 

 

OUTPUT SAVE OUTFILE = "D:\Temp\Test.spv".

OUTPUT CLOSE *.

 

* Python code 1.

***************.

 

BEGIN PROGRAM.

import spss,  SpssClient, viewer, time

OpenFile = "OUTPUT OPEN FILE = 'D:/Temp/Test.spv'."

SaveFile = "OUTPUT SAVE OUTFILE = 'D:/Temp/Test.spv'."

 

SpssClient.StartClient()

try:   

    spss.Submit(r"""

    %s

    """ %(OpenFile))

 

    OutputItems = SpssClient.GetDesignatedOutputDoc().GetOutputItems()

    itemcount = OutputItems.Size()

    OutputItem = OutputItems.GetItemAt(itemcount - 1)

 

    myWidth = [0,100, 80, 30]

 

    if OutputItem.GetType() == SpssClient.OutputItemType.PIVOT:

        PivotTable = OutputItem.GetSpecificType()

        PivotTable.SetUpdateScreen(False)

        PivotTable.SetDataCellWidths(55)

        #time.sleep(0.5)

        rowlabels = PivotTable.RowLabelArray()

       

        PivotTable.SetUpdateScreen(True)

 

    spss.Submit(r"""

    %s

    """ %(SaveFile))

 

    spss.Submit(r"""

    OUTPUT CLOSE *.

    """)

 

finally:

    SpssClient.StopClient()

 

END PROGRAM.

 

 

 

 

* This works.

 

* Python code 1.

***************.

 

OUTPUT OPEN FILE = 'D:/Temp/Test.spv'.

 

BEGIN PROGRAM.

import SpssClient

SpssClient.StartClient()

try:

    OutputDoc = SpssClient.GetDesignatedOutputDoc()

    OutputItems = OutputDoc.GetOutputItems()

 

    myWidth = [0,100, 80, 30]

    for index in range(OutputItems.Size()):

        OutputItem = OutputItems.GetItemAt(index)

        if OutputItem.GetType() == SpssClient.OutputItemType.PIVOT:

            if OutputItem.GetType() == SpssClient.OutputItemType.PIVOT:

                PivotTable = OutputItem.GetSpecificType()

                PivotTable.SetUpdateScreen(False)

 

                x = 1

                while x < 1000:

                    rowlabels = PivotTable.RowLabelArray()

                    for i in range(rowlabels.GetNumRows()):

                        for j in range(rowlabels.GetNumColumns()):

                            rowlabels.SetRowLabelWidthAt(i,j,myWidth[j])

                            print x

                            x = x + 1

                PivotTable.SetUpdateScreen(True)

 

finally:

    SpssClient.StopClient()

END PROGRAM.

 

 

**********************************
la volta statistics

Christian Schmidhauser, Dr.phil.II
Weinbergstrasse 108
CH-8006 Zürich
Tel: +41 (043) 233 98 01
Fax: +41 (043) 233 98 02
email:
[hidden email] 
Web:
www.lavolta.ch