Skip to content

Add conversion of state label columns to str if necessary#22

Merged
ianmkenney merged 3 commits intoBecksteinlab:masterfrom
l-repa:string-checking
Dec 18, 2023
Merged

Add conversion of state label columns to str if necessary#22
ianmkenney merged 3 commits intoBecksteinlab:masterfrom
l-repa:string-checking

Conversation

@l-repa
Copy link
Copy Markdown
Contributor

@l-repa l-repa commented Dec 13, 2023

pd.read_csv by default sets columns to int or float if they are purely numeric, which causes the string matching done later to fail and return an empty dataframe (which then throws an error when attempting to access its elements)

pd.read_csv by default sets columns to int or float if they are purely numeric, which causes the string matching done later to fail and return an empty dataframe (which then throws an error when attempting to access its elements)
@orbeckst orbeckst requested a review from ianmkenney December 15, 2023 16:12
Copy link
Copy Markdown
Member

@ianmkenney ianmkenney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pandas uses object arrays for strings because of their variable length and is really an issue for performance. I'm not sure how long the object solution will work. It might break if they change string representations. For instance see this experimental feature in pandas.

https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.StringDtype.html#pandas.StringDtype

I would instead suggest we tell read_csv which datatypes are needed for each column. You can specify str for the state columns and it will default to the object datatype. I assume that if they change how they represent strings, this will still work.

@l-repa
Copy link
Copy Markdown
Contributor Author

l-repa commented Dec 15, 2023

Good idea, changed to use dtype kwarg in pd.read_csv instead to specify the state columns should be str.

Comment thread multibind/nonequilibrium.py Outdated
Copy link
Copy Markdown
Member

@ianmkenney ianmkenney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @l-repa

@ianmkenney ianmkenney merged commit 3fbf9fb into Becksteinlab:master Dec 18, 2023
@l-repa l-repa deleted the string-checking branch December 18, 2023 20:58
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 this pull request may close these issues.

2 participants