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

Print keys if not unique #1158

Open
riverscuomo opened this issue Dec 31, 2022 · 3 comments
Open

Print keys if not unique #1158

riverscuomo opened this issue Dec 31, 2022 · 3 comments
Assignees

Comments

@riverscuomo
Copy link

Is your feature request related to a problem? Please describe.
My problem is with worksheet.get_all_records(). Gspread 5.7.2.

I have some large sheets that somehow acquired duplicate headers. This caused an exception because "the given 'expected_headers' are not uniques". Because I had so many headers, it was hard to find and delete the duplicates.

Describe the solution you'd like
I added a check on the sheet keys that prints any duplicates as part of the exception.

if duplicate_keys := [x for x in keys if keys.count(x) > 1]:
            raise GSpreadException(f"these headers are not uniques: {duplicate_keys}")

image

Describe alternatives you've considered
At first I added a print statement to the existing check:

        # make sure they are uniques
        if len(expected) != len(expected_headers):
            print([x for x in keys if keys.count(x) > 1])
            raise GSpreadException("the given 'expected_headers' are not uniques")
@lavigne958
Copy link
Collaborator

Hi this is an interesting feature request.

In the method get_all_records you can specify which header is not unique and which you don't care about not being unique. For sure that implies Knowing the index of those headers.

Generally speaking, printing informations as result to the end user is not practical when developing a library as gspread is not the final, end user facing app, so we always need to return information and the app that used gspread will take care of printing it or do something with it

What we can do is: add a new method to return all non uniques headers, or only the indexes of headers that are not uniques, or a map with the keys being the indexes and the value being the header. something like that could work.

@riverscuomo
Copy link
Author

Thank you for the reply.

Generally speaking, printing informations as result to the end user is not practical when developing a library as gspread is not the final, end user facing app, so we always need to return information and the app that used gspread will take care of printing it or do something with it

I didn't know that. I've never made a library before. But now that you mention it, I don't remember seeing libraries print much information before.

What we can do is: add a new method to return all non uniques headers,

I think you mean I could call the method to check for non-uniques before calling get_all_records(). That would be great.

@lavigne958
Copy link
Collaborator

Thank you for the reply.

Generally speaking, printing informations as result to the end user is not practical when developing a library as gspread is not the final, end user facing app, so we always need to return information and the app that used gspread will take care of printing it or do something with it

I didn't know that. I've never made a library before. But now that you mention it, I don't remember seeing libraries print much information before.

What we can do is: add a new method to return all non uniques headers,

I think you mean I could call the method to check for non-uniques before calling get_all_records(). That would be great.

Yes that what I mean 🙂

For this to be useful, the method should return the list of headers that are not uniques and provide the indexes for these headers so it can be used and passed to the method get_all_records.

I still need to clarify the returned format .

@lavigne958 lavigne958 self-assigned this Feb 2, 2023
@alifeee alifeee added this to the 6.0.0 milestone Aug 8, 2023
@alifeee alifeee removed this from the 6.0.0 milestone Oct 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants