Skip to content

SPSS: variable_value_label becomes None if any string value is longer than 8 characters #264

Description

@wilfredrial

Hi, not sure how to tell if this is an issue in the c library or pyreadstat. Apologies if it is the former.

As the title says, the "Values" column becomes "None" for a String variable in SPSS if any value is longer than 8 characters.

To reproduce:

import pandas as pd
import pyreadstat

var_values = {'mycol':{'-111':'err1'}}

# I thought setting var_format might have an effect but it seems it does not
# just leaving this here in case you want to compare
var_format = {} # {'mycol':'A50'} 

pyreadstat.write_sav(df=pd.DataFrame({'mycol':['-111', '123456789']}),  # 2nd value is 9 chars
                     dst_path='var_values_is_none.sav', 
                     variable_value_labels=var_values,
                     variable_format=var_format)


pyreadstat.write_sav(df=pd.DataFrame({'mycol':['-111', '12345678']}), # 2nd value is 8 chars
                     dst_path='var_values_is_NOT_none.sav', 
                     variable_value_labels=var_values,
                     variable_format=var_format)

Relevant versions:
python 3.12.3
pyreadstat 1.2.7
pandas 2.2.2

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingrequires changes in Readstatwaiting for changes in the C library Readstat

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions