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.

`get_values` does not return all data in some scenarios with empty data

See original GitHub issue

Hello! Thanks for your time. I wanted to report a potential bug in the get_values function. When you have a spreadsheet that has say 6 columns with headers, where data should be and you make a query for a particular row, there is a certain scenario where empty data fields are not returned. This can be confusing for downstream users of the gspread API who want to say, convert the row into a dictionary (ala get_all_records).

This scenario occurs when data is laid out like this:

header1, header2, header3, header4, header5, header6
x1, , , x4, ,

In that data above header5 and header6 are empty for the first row. Suppose you made this call:

ws.get_values("A1:1")

You only get back:

[['x1',,,'x4']]

As opposed to what I would expect:

[['x1',,,'x4',,]]

Minimal reproducer:

Screen Shot 2021-08-17 at 11 17 03 AM
(Pdb++) ws.get_values("A7:7")
[['', 'kl3020', '', '07/26/2021']]

Expected result:

(Pdb++) ws.get_values("A7:7")
[['', 'kl3020', '', '07/26/2021', '', '']]

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
lavigne958commented, Oct 28, 2021

You’re right, issue re-open. If you have a PR ready feel free to open it I’ll review it.

Thanks.

1reaction
ccppoocommented, Oct 30, 2021

This is sample worksheet with name ‘test’

A B C D E F
1 ID NAME math science python rock
2 9938 aaaa _ _ 90 _
3 9738 bbbb 30 _ 55 45
4 4821 cccc _ 40 _ _
5 3908 dddd _ _ 100 _
6 7182 eeee _ 90 _ 80

* in this example, _(underbar) means empty cell

* ROWs : 1 … 6 // COLs : A … F

... # auth stuffs

ws = spreadSheet.worksheet('test')

case 1. when requesting values A1:E3 (expectable)

result = ws.get_values('A1:E3')
# result
[
    ['ID', 'NAME', 'math', 'science', 'python'],
    [9938, 'aaaa', '', '', 90 ],
    [9738, 'bbbb', 30, '', 55]
]

case 2. when requesting values C1:E3 (expectable)

result = ws.get_values('C1:E3')
# result
[
    ['math', 'science', 'python'],
    ['', '', 90 ],
    [30, '', 55]
]

case 3. when requesting values A1:F2 (expectable)

result = ws.get_values('A1:F2')
# result
[
    ['ID', 'NAME', 'math', 'science', 'python', 'rock'],
    [9938, 'aaaa', '', '', 90, '' ],
]

edit added : use case for pandas.DataFrame

result = ws.get_values('A1:F2')
df2 = pands.DataFrame(result)

print(df2)
#    ID    NAME      math    science   python   rock
# 0  9938  aaaa                        90

case 4. when requesting values A2:F2 (quite not expectable)

result = ws.get_values('A2:F2')
# result
[
    [9938, 'aaaa', '', '', 90],
]

what some people would have expected :

[
    [9938, 'aaaa', '', '', 90, '']
]

comparing with case 2 and case 4,

we could know google search from left to right

but don’t take into account when cell is empty

just like they are using str.rstrip() python string method

tl;dr google spread request return results after using rstrip()-like method

any thing to fix?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Stuck on SqlDataReader.GetValues Method - Stack Overflow
To accomplish this, it seems that the GetValues method would return what I need, which is the entire dataset the stored procedure is...
Read more >
Retrieve Rows from Google Spreadsheet with Google Apps ...
The concept of data range is important since some rows may not have data in all columns, so blank values will be included...
Read more >
useForm - getValues - React Hook Form
An optimized helper for reading form values. The difference between watch and getValues is that getValues will not trigger re-renders or subscribe to...
Read more >
Retrieving Data | Firebase Realtime Database - Google
That means the SDK does not register any callbacks that listen to subsequent data updates. This model of data retrieval is supported in...
Read more >
Reading from and writing to a Range in Google Sheets using ...
This tutorial will walk you through several ways to read data from and write data to your Google Sheets spreadsheet using Google Apps...
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