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

"ValueError: 'col1' is not in list" when using "select" argument in DataPortal().load() #461

Closed
fuma900 opened this issue May 2, 2018 · 1 comment
Labels
enhancement not planned pyomo.data Any issues related to data portals and data file parsing

Comments

@fuma900
Copy link

fuma900 commented May 2, 2018

Context

I'm using Python 3.6.5 and pyomo 5.5.0.

data = DataPortal(model=m)
data.load(
    filename='data.csv',
    index=('hours', 'UPs'),
    select=('col1', 'col2', 'col3', 'col4', 'col5', 'col6'),
    param=('availability', 'pun', 'pz', 'msdDownPrice', 'msdDownMaxQty', 'msdUpPrice')
)

Problem

Trying to load a csv file into the model through DataPortal i'm getting this error:
ValueError: 'col1' is not in list
The csv is well formatted and its headers are successfully parsed using 3rd parties libraries (e.g. pandas' read_csv).

Solution

Debugging the problem i found out that the headers were parsed as ['col1', 'col2', 'col3', ... ].
Thanks to this SO post i was able to address the issue by changing the encoding from python default to encoding='utf-8-sig' in csv_table.py - line 37.
I guess the issue was primarily caused by excel's "save as csv" function which most probably prepend a UTF-8 Byte Order Mark.

I think it could be useful to expose an optional encoding argument in the load function to let developers manage encoding-related issues on their own.

@blnicho blnicho added enhancement pyomo.data Any issues related to data portals and data file parsing labels May 10, 2018
@mrmundt
Copy link
Contributor

mrmundt commented Jan 3, 2024

In an effort to clean up issues, we are moving some discussions to our Archived Design Discussions wiki.

@mrmundt mrmundt closed this as completed Jan 3, 2024
@blnicho blnicho closed this as not planned Won't fix, can't repro, duplicate, stale Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement not planned pyomo.data Any issues related to data portals and data file parsing
Projects
None yet
Development

No branches or pull requests

3 participants