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

Dataframe columns with lists in them do not work #6

Closed
schwallie opened this issue Jul 26, 2017 · 8 comments
Closed

Dataframe columns with lists in them do not work #6

schwallie opened this issue Jul 26, 2017 · 8 comments

Comments

@schwallie
Copy link

schwallie commented Jul 26, 2017

Got an error on what I think is a column with a list in it:

  File "get_paypal.py", line 789, in main
    donor, wkb='OTAT Donor Database', wks='DonorLevel')
  File "/Users/---/Desktop/repos/otat/config.py", line 246, in upload_to_google
    set_with_dataframe(worksheet, df, include_index=True)
  File "/usr/local/lib/python2.7/site-packages/gspread_dataframe.py", line 185, in set_with_dataframe
    _cellrepr(cell_value, allow_formulas))
  File "/usr/local/lib/python2.7/site-packages/gspread_dataframe.py", line 51, in _cellrepr
    if pd.isnull(value):
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()```
@robin900
Copy link
Owner

Ok, I'll explore how to make the null check not raise an exception regardless of the value type. But I have a question: when the array value was written to a cell in the google spreadsheet, what were you expecting it to look like? A comma-delimited string? A space-delimited string? A Python array literal?

@schwallie
Copy link
Author

schwallie commented Jul 26, 2017 via email

@robin900
Copy link
Owner

OK, my next question is: if you write a Python list literal to a Google spreadsheet cell, are you expecting to 1) read it back into a dataframe; and 2) if so, are you expecting it to be parsed back into a Python list object?

I can accept 1) being "yes", as long as 2) is "no", because I have to defer to pandas.read_csv's behavior, and it's always going to read a cell inputValue of [1,2,3] as the string "[1, 2, 3]".

@schwallie
Copy link
Author

schwallie commented Jul 26, 2017 via email

@robin900
Copy link
Owner

Yes, I actually never use them. While I contemplate over the next 12 hours how best to code a fix for this, your best workaround is to do a str(list_value) and use the result as the value to assign to that cell in the dataframe.

robin900 pushed a commit that referenced this issue Jul 26, 2017
…ell values

in a DataFrame. Deal with regression where float precision is mangled
during round-trip testing, by using repr() on float values and str()
on other values.

Fixes #6.
@robin900
Copy link
Owner

@schwallie Would you like to checkout the branch referenced by the pull request (rbt-accept-list-value-for-cell) and test it with your own code? You can also run python setup.py test to run the included test suite. With your approval, I'll proceed with a new PyPI release.

@schwallie
Copy link
Author

Awesome, thanks. lgtm 💯

robin900 added a commit that referenced this issue Jul 27, 2017
…ell values (#7)

in a DataFrame. Deal with regression where float precision is mangled
during round-trip testing, by using repr() on float values and str()
on other values.

Fixes #6.
@robin900
Copy link
Owner

@schwallie Release 2.1.0 is now on PyPI. (Because of the change in the code of how floats are represented in cell values submitted to Google sheet API, I bumped the minor version to 2.1 rather than make a bugfix version of 2.0.2.)

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

No branches or pull requests

2 participants