question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

buggy behavior when dealing with decimals?

See original GitHub issue

Hey, I am dealing with this behavior and I don’t know if its a bug or I am doing something wrong:

import pandas as pd
import numpy as np
import gspread
import gspread_dataframe
from gspread_dataframe import set_with_dataframe
gc = gspread.service_account()
sh = gc.open('pandas_spreadsheet')
worksheet = sh.get_worksheet(0)

test_df = pd.DataFrame.from_records([{'a': i/500 + np.random.randn(), 'b': i * 2} for i in np.arange(0,1000,100)])
test_df
set_with_dataframe(worksheet, test_df)

Expected: Screen Shot 2020-10-08 at 15 10 39

Obtained: image

And if i go to the cell A1 and copy the cell value is -9622382525353560 I thought it was something with the formatting, but this number is not a float.

If I export the df using set_with_dataframe(worksheet, test_df.round(3)) I obtain the following: image

And this is a the same test in a new blank worksheet (to avoid any kind of previous formatting problems)

image

Please let me know if there is something that I can do to help you with a PR.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
robin900commented, Oct 9, 2020

@ivanlen I suspect that a Google spreadsheet’s locale settings determine not just the default display formatting of numbers and dates, but also the parsing format rules when interpreting cell value inputs that are in mode USER_ENTERED.

Would you be willing to try the following:

  1. Manually change the locale for this Google spreadsheet to “United States”. With the sheet open in a browser, visit File->Spreadsheet settings. Then run your Python script again and see if the float values are parsed correctly as floats.

  2. If everything works fine for your script once spreadsheet locale is “United States”, then post here what your original locale was, and we will proceed from there.

(I suspect the solution to the problem will be either:

A) Allow overrides to the valueInputOption value included in Sheets API cell updates; currently the package uses USER_ENTERED to take advantage of the powerful value parsing logic in Sheets, but it’s apparently that some users need to bypass USER_ENTERED.

B) Add locale awareness to set_with_dataframe in some fashion, so that formatting inputs using values from the dataframe take the expected locale of the spreadsheet into consideration.)

1reaction
robin900commented, Oct 14, 2020

@ivanlen Release 3.1.1 with this fix ya está en PyPI. Gracias por su ayuda!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Decimal-Misconceptions-Remediation.pdf - A Learning Place
Shorter-is-larger (S) behaviour: choosing the decimal with the fewest digits after the decimal point as the largest. While these may seem incredibly naïve ......
Read more >
Misconceptions about Decimal Numbers - Extranet
Apparent-Expert Behavior These students can generally decide which of two decimals is larger but sometimes not for the right reasons.
Read more >
printf does not properly format decimals when using '%.8F'
Bug #78265, printf does not properly format decimals when using '%.8F' ... but there are perhaps libraries that expect the buggy behavior at ......
Read more >
Javascript parse float is ignoring the decimals after my comma
Eh, no. That is seriously buggy by design. What if you are parsing a number from the 50% of the world that is...
Read more >
Three decimal dimensions truncated to two ... - PTC Community
Several of these 2 decimal dimensions have been entered into family tables, and they show up as two decimal numbers, which I believe...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found