pylhc / tfs

Python package to handle TFS files
https://pylhc.github.io/tfs/
MIT License
9 stars 4 forks source link

[Bug]: No longer able to write out Series #129

Closed JoschD closed 8 months ago

JoschD commented 8 months ago

Documentation

Operating System

All

Python Version

3.9

Package Version

3.7.2

Bug Description

I have old code in which I gave a pd.Series object to the write-function and it wrote it into a .tfs file. With one of the checks, we seem to have broken this "feature". Maybe we should bring it back.

Steps to Reproduce

tfs.write("blubb", pd.Series([1,2,3,4]))

Relevant output

File "/afs/cern.ch/work/j/jdilly/public/venvs/acc-py-editable/src/tfs-pandas/tfs/writer.py", line 102, in write_tfs
    validate_frame(data_frame, f"to be written in {tfs_file_path.absolute()}", non_unique_behavior)
  File "/afs/cern.ch/work/j/jdilly/public/venvs/acc-py-editable/src/tfs-pandas/tfs/frame.py", line 281, in validate
    if data_frame.columns.has_duplicates:
  File "/afs/cern.ch/work/j/jdilly/public/venvs/acc-py-editable/lib/python3.9/site-packages/pandas/core/generic.py", line 6296, in __getattr__
    return object.__getattribute__(self, name)
AttributeError: 'Series' object has no attribute 'columns'

Possible Fix Implementation

check if pd.Series or try-except Attribute Error or ...

fsoubelet commented 8 months ago

Good catch! In the meantime, does it work if you provide validate=False to the writer? Seems line 118 would still be an issue.