Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sav variable display width becomes 0 if string variables longer than 255 characters #210

Closed
ofajardo opened this issue Aug 28, 2020 · 7 comments
Labels

Comments

@ofajardo
Copy link

ofajardo commented Aug 28, 2020

I am using readstat_variable_set_display_width to set the variable display width when writing a sav file. It is working, meaning when reading the written file I can get the display variable width with readstat_variable_get_display_width and it looks correct.

However if the dataset contains a value which is a string with 256 characters or more, writing it and reading again, then when using readstat_variable_get_display_width I get 0, interestingly not only for the variable containing the long string, but for any other variable in the dataset.

The long string itself is read correctly.

@evanmiller
Copy link
Contributor

Thank you for the report. Please try 03ba85c

@ofajardo
Copy link
Author

ofajardo commented Aug 28, 2020

it works! thanks!

Just one more question: it seems that the max value is 255, if I enter something higher it goes back to 255. Is that intentional? (SPSS does accet widths larger than 255)

@evanmiller
Copy link
Contributor

The display width is stored in two separate places. In the "legacy" location the width is limited to 255. In the new location there is no limit. I will need to tinker with it some more to make sure the proper location is used.

@evanmiller
Copy link
Contributor

Can you provide a test case and ensure you are using the latest code? My tests pass using display widths of e.g. 1000.

@ofajardo
Copy link
Author

ofajardo commented Aug 28, 2020

hmm, attached the python script I am using, and the resulting file, setting it to 1000 and I recover 255 from readstat_variable_get_display_width (I am also printing the call to readstat_variable_get_display_width internally, not in the script, Im printing just below this line
https://github.com/Roche/pyreadstat/blob/dev/pyreadstat/_readstat_parser.pyx#L474)

PSPP in the other hand says it is correct (1000) ... so now I am confused

Archive.zip

@evanmiller
Copy link
Contributor

Try this 3fe313f

It looks like the display record was not being read correctly with long strings. I didn't notice this before because the function's return value was never checked (and short strings were fine).

@ofajardo
Copy link
Author

yes, that fully solves it!

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants