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

Cannot open xpt files with the latest xport dependency version #2364

Open
v opened this issue Mar 26, 2024 · 2 comments
Open

Cannot open xpt files with the latest xport dependency version #2364

v opened this issue Mar 26, 2024 · 2 comments
Labels

Comments

@v
Copy link

v commented Mar 26, 2024

Small description

visidata needs a specific version of the xport package to open XPT files, but this isn't specified in the requirements anywhere

Expected result

Should open xpt files.

Actual result with screenshot

image

Traceback (most recent call last):
File "/Users/vaibhav/.pyenv/versions/3.11.5/envs/onc/lib/python3.11/site-packages/visidata/threads.py", line 220, in _toplevelTryFunc
t.status = func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/vaibhav/.pyenv/versions/3.11.5/envs/onc/lib/python3.11/site-packages/visidata/sheets.py", line 260, in reload
self.loader()
File "/Users/vaibhav/.pyenv/versions/3.11.5/envs/onc/lib/python3.11/site-packages/visidata/sheets.py", line 285, in loader
for r in self.iterload():
File "/Users/vaibhav/.pyenv/versions/3.11.5/envs/onc/lib/python3.11/site-packages/visidata/loaders/sas.py", line 25, in iterload
for i, var in enumerate(self.rdr._variables):
^^^^^^^^^^^^^^^^^^^
File "/Users/vaibhav/.pyenv/versions/3.11.5/envs/onc/lib/python3.11/site-packages/xport/__init__.py", line 849, in __getattr__
return getattr(self.dataset, name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/vaibhav/.pyenv/versions/3.11.5/envs/onc/lib/python3.11/site-packages/pandas/core/generic.py", line 5487, in __getattr__
return object.__getattribute__(self, name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Member' object has no attribute '_variables'

My locally installed versions of visidata and xport are as follows:

$ pip show xport
Name: xport
Version: 3.6.1
Summary: SAS XPORT file reader
Home-page: https://github.com/selik/xport
Author: Michael Selik
Author-email: michael.selik@gmail.com
License: MIT
Location: /Users/vaibhav/.pyenv/versions/3.11.5/envs/onc/lib/python3.11/site-packages
Requires: click, pandas, pyyaml
Required-by: 
$ pip show visidata
Name: visidata
Version: 3.0.2
Summary: terminal interface for exploring and arranging tabular data
Home-page: https://visidata.org
Author: Saul Pwanson
Author-email: visidata@saul.pw
License: GPLv3
Location: /Users/vaibhav/.pyenv/versions/3.11.5/envs/onc/lib/python3.11/site-packages
Requires: importlib-metadata, python-dateutil
Required-by: 

Steps to reproduce with sample data and a .vd

  1. Download this xpt file:

https://github.com/prasertcbs/basic-dataset/blob/8c80eb454b2defd3db217d8f95883eb6a1e3f263/brakes.xpt

  1. Open it using visidata, and notice that you get the exception above.
AttributeError: 'Member' object has no attribute '_variables'
  1. If I pip install 'xport<3', visidata opens the file just fine.

Additional context
Please include the version of VisiData and Python.

Visidata version included above.

Python version:

$ python --version
Python 3.11.5
@v v added the bug label Mar 26, 2024
@midichef
Copy link
Contributor

Thanks for pointing this out, @v.

It appears that visidata relies on behavior from xport v2, and xport v3 has changed how to read files:

v3.0.0, 2020-04-20
Revise API to the load/dump pattern. Enable specifying dataset name, variable names, labels, and formats.

Perhaps visidata should switch to using xport v3's load() for reading files.

As a side note, while investigating the xport v2 format, I noticed the .xpt loader has a bug. It will cause inability to edit cells, and possibly odd behavior when selecting rows. I've proposed a fix here: #2365
If you run into such problems, you may want to apply that fix. If not, an alternate workaround would be to save .xpt files right after opening them, in some other format (like .tsv or .json). Then reopen the new .tsv file in visidata.

@midichef
Copy link
Contributor

I've drafted a fix to update visidata's use of xport from xport v2 to v3.6.1. I'm unfamiliar with SAS and Pandas, so I cannot test it thoroughly. But it does seem to give the same results as Visidata v3.0 for this 2-column test file of numbers: https://github.com/prasertcbs/basic-dataset/blob/8c80eb454b2defd3db217d8f95883eb6a1e3f263/brakes.xpt.

I'll leave the draft here as a starting point for anyone who wants to work with it in the future: 793ec73

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