Assertion during creating of multRespDefs

Issue #4 resolved
Former user created an issue

Your example of creating multRespDefs doesn't work

                categorical  = {"setType": "C", "label": "labelC",
                                "varNames": ["salary", "educ"]}
                dichotomous1 = {"setType": "D", "label": "labelD",
                                "varNames": ["salary", "educ"], "countedValue": "Yes"}
                dichotomous2 = {"setType": "D", "label": "", "varNames":
                    ["salary", "educ", "jobcat"], "countedValue": "No"}
                extended1    = {"setType": "E", "label": "", "varNames": ["mevar1",
                                                                          "mevar2", "mevar3"], "countedValue": "1",
                                "firstVarIsLabel": True}
                extended2    = {"setType": "E", "label":
                    "Enhanced set with user specified label", "varNames":
                                    ["mevar4", "mevar5", "mevar6"], "countedValue":
                                    "Yes", "firstVarIsLabel": False}
                multRespDefs = {"testSetC": categorical, "testSetD1": dichotomous1,
                                "testSetD2": dichotomous2, "testSetEx1": extended1,
                                "testSetEx2": extended2}

with SavWriter(savFileName, varNames, varTypes, varLabels=varLabels, formats=formats, multRespDefs = multRespDefs, ioUtf8=True) as sav:
                    for record in records:
                        sav.writerow(record)

it failed on this line in header.py: 1044

retcode = func(c_int(self.fh), c_char_p(combinedDefs))

with output:

testSetD1 {'varNames': ['salary', 'educ'], 'label': 'labelD', 'countedValue': 'Yes', 'setType': 'D'} D
testSetEx2 {'varNames': ['mevar4', 'mevar5', 'mevar6'], 'firstVarIsLabel': False, 'label': 'Enhanced set with user specified label', 'countedValue': 'Yes', 'setType': 'E'} E
testSetEx1 {'varNames': ['mevar1', 'mevar2', 'mevar3'], 'firstVarIsLabel': True, 'label': '', 'countedValue': '1', 'setType': 'E'} E
testSetD2 {'varNames': ['salary', 'educ', 'jobcat'], 'label': '', 'countedValue': 'No', 'setType': 'D'} D
testSetC {'varNames': ['salary', 'educ'], 'label': 'labelC', 'setType': 'C'} C
python: /buildhome/statbldr/views/builder1unix_spss21000_view/cs_source/Datasource/src/variableset.cpp:163: size_t GetSize(std::string&): Assertion `length != 0' failed.

Is it bug or I just use wrong format?

Thank you in advance

Comments (5)

  1. Albert-Jan Roskam repo owner

    No, not immediately, but it is possible to pip install straight from the repository:

    pip install -U -e git+https://bitbucket.org/fomcl/savreaderwriter.git#egg=savreaderwriter
    

    I realized that I still need to modify the code a little to also make it work in unicode mode (ioUtf8=True). Judging from your name you are from a Slavian country. So instead of switching to unicode mode you might also try setting the SPSS I/O locale to something like ioLocale="ru_RU.cp1251". That has the advantage of smaller file size (utf-8 is bigger than codepage) and greater speed (transcoding causes overhead).

  2. Alexandra Isaenko

    Thank you, I will switch standart pip to the repository.

    No, I live and work in Germany and I use UTF-8, because we use different languages, not only german. But thank you for this advice and for this plugin.

  3. Albert-Jan Roskam repo owner

    Fixed. Writing dichotomy MR definitions should work now, including in unicode mode (ioUtf8=True). "Extended" multiple response definitions can only be read, not written (as per documentation).

  4. Log in to comment