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

Read in a range as list? #40

Open
fzumstein opened this issue Oct 12, 2023 · 3 comments
Open

Read in a range as list? #40

fzumstein opened this issue Oct 12, 2023 · 3 comments
Labels
documentation Improvements or additions to documentation question Further information is requested

Comments

@fzumstein
Copy link

I am aware of the possibility to override the excel.set_xl_array_conversion with something like excel.set_xl_array_conversion(convert_to_list). But is there a way to leave the default as DataFrame, and just occasionally get a list, or is the idea to convert the DataFrame back to a list to do this?

@keyur32
Copy link
Collaborator

keyur32 commented Oct 13, 2023

The xl() function signature supports **kwargs, so you can pass additional parameters which are then pass to the conversion function, i.e. xl("A1:B5", headers=True, to_list=True)

Then check that to_list parameter as part of our convert_to_list and implement your logic accordingly.

@keyur32 keyur32 added documentation Improvements or additions to documentation question Further information is requested labels Oct 13, 2023
@keyur32
Copy link
Collaborator

keyur32 commented Oct 13, 2023

Tagging as documentation (for when we enable support for editing of the Initialize pane).

@fzumstein
Copy link
Author

Actually, I think overriding the default converter is easier. This is what I came up with:

def myconverter(x, headers=False, convert=None, **kwargs):
    if convert is None or convert == pd.DataFrame:
        return excel.convert_to_dataframe(x, headers=headers, **kwargs)
    elif convert == np.array:
        return np.array(x)
    elif convert == list:
        return x

excel.set_xl_array_conversion(myconverter)

This keeps the default unchanged, but allows for these:

xl(..., convert=np.array)
xl(..., convert=list)

As long as the initialize pane isn't editable, this can be placed in A1 of the first sheet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants