Skip to content

Error on pyreadstat.write_sav with ver 1.3.1 #306

@albertxli

Description

@albertxli

Hi,

Reading an excel datafile, and trying to give it some labels for column headers and date values then save as .sav file. But ran into issue while writing into sav. please use this demo data to reproduce the error.

import pandas as pd
import pyreadstat


file_path = "demo.xlsx"
df = pd.read_excel(file_path)

output_path = "demo.sav"
pyreadstat.write_sav(df, output_path)

got the following error:

    pyreadstat.write_sav(df, output_path)
    ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "pyreadstat/pyreadstat.pyx", line 784, in pyreadstat.pyreadstat.write_sav
  File "pyreadstat/_readstat_writer.pyx", line 730, in pyreadstat._readstat_writer.run_write
  File "pyreadstat/_readstat_writer.pyx", line 333, in pyreadstat._readstat_writer.get_narwhals_column_types
  File "pyreadstat/_readstat_writer.pyx", line 227, in pyreadstat._readstat_writer.get_narwhals_str_series_max_length
AttributeError: 'datetime.datetime' object has no attribute 'encode'

I have ran the same code with pyreadstat 1.3.0 and save process was smooth without issues. It seems that the underlying narwhals library is complaining about the object data type from pandas. Let me know if you encounter the same problem with the demo data.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions