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

write_sav: uninformative error message for empty column names #276

Open
MarkPaulin opened this issue Nov 8, 2024 · 1 comment · May be fixed by #277
Open

write_sav: uninformative error message for empty column names #276

MarkPaulin opened this issue Nov 8, 2024 · 1 comment · May be fixed by #277

Comments

@MarkPaulin
Copy link

Describe the issue

write_sav() doesn't give a particularly informative error message when trying to write a data frame with an empty string as a column name. If a column has a column named None, you get a much clearer error message.

To Reproduce

import pandas as pd
import pyreadstat

df1 = pd.DataFrame({"a": [1, 2], "": [3, 4]})
pyreadstat.write_sav(df1, "file.sav")
#> Traceback (most recent call last):
#>   File "<stdin>", line 1, in <module>
#>   File "pyreadstat\\pyreadstat.pyx", line 772, in pyreadstat.pyreadstat.write_sav
#>   File "pyreadstat\\_readstat_writer.pyx", line 598, in pyreadstat._readstat_writer.run_write
#> IndexError: string index out of range

df2 = pd.DataFrame({"a": [1, 2], None: [3, 4]})
pyreadstat.write_sav(df2, "file.sav")
#> Traceback (most recent call last):
#>   File "<stdin>", line 1, in <module>
#>   File "pyreadstat\\pyreadstat.pyx", line 772, in pyreadstat.pyreadstat.write_sav
#>   File "pyreadstat\\_readstat_writer.pyx", line 597, in pyreadstat._readstat_writer.run_write
#> pyreadstat._readstat_parser.PyreadstatError: variable name 'None' is of type <class 'NoneType'> and it must be str (not starting with numbers!)

I'm happy to submit a pull request to add an error for empty strings in line with Nones.

@ofajardo
Copy link
Collaborator

ofajardo commented Nov 8, 2024

Good catch! Please go ahead with the PR!

@MarkPaulin MarkPaulin linked a pull request Nov 8, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants