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

get_all_records => provided headers #1527

Open
nick-youngblut opened this issue Oct 29, 2024 · 6 comments
Open

get_all_records => provided headers #1527

nick-youngblut opened this issue Oct 29, 2024 · 6 comments

Comments

@nick-youngblut
Copy link

get_all_records does not allow one to specify the headers if there is no header row. One can only skip rows via head or set the expected headers via expected_headers, but one cannot specify the header (column) names. This feature would be quite helpful when there is no header in the table.

@alifeee
Copy link
Collaborator

alifeee commented Oct 29, 2024

hi !! thanks for your request :)

the docs mention gspread.utils.to_records, which can be used like so:

apple red circle very
banana yellow stick quite
papaya seedy seedy
import gspread
SPREADSHEET_ID = "uhfa3897fu3a987f389a8jf38af"
gc = gspread.service_account(filename="./creds.json")
spreadsheet = gc.open_by_key(SPREADSHEET_ID)
worksheet = spreadsheet.sheet1

headers = ["fruit", "alternate name", "tastiness"]
values = worksheet.get()
records = gspread.utils.to_records(headers, values)
for r in records:
    print(r)
# {'fruit': 'apple', 'alternate name': 'red circle', 'tastiness': 'very'}
# {'fruit': 'banana', 'alternate name': 'yellow stick', 'tastiness': 'quite'}
# {'fruit': 'papaya', 'alternate name': 'seedy', 'tastiness': 'seedy'}

I believe this is what you desire.

However, it is clear the documentation was not clear in explaining this possibility. Perhaps it could do with an example.

Would you be willing to write an example to improve the documentation ?

Thanks !! :]

@nick-youngblut
Copy link
Author

Thanks @alifeee for the info!

Could get_all_records be updated so that users can specify custom headers, so that developers can just use get_all_records for cases in which a header exists or does not?

@alifeee
Copy link
Collaborator

alifeee commented Oct 30, 2024

generally we are trying to stop feature creep for get_all_records. See #1367 and surrounding issues/PRs for more information, but we had to pull back the scope because of bugs.

There is potential that this feature is "simple enough" to be a good cause for addition, but I think the "workaround" (using utils.to_records is a perfectly fine solution, but perhaps needs more signposting in the documentation for the method (i.e., with an example) as I said

so... no ;]

@lavigne958
Copy link
Collaborator

Hi as alifee said, we stopped adding features to get_all_records. We want it to be as simple as possible and it's already quiet complex as is.

Closing this issue.

@alifeee
Copy link
Collaborator

alifeee commented Oct 31, 2024

@lavigne958 thank you. But the creation of an issue is an example that our documentation has room for improvement, so we should improve it, thus I open the issue for this purpose

@alifeee alifeee reopened this Oct 31, 2024
@lavigne958
Copy link
Collaborator

Agreed, sorry for the prompt action. You're right 👍

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

3 participants