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

Allow to disable skipping empty rows/columns at the beginning of the worksheet #209

Open
wikiped opened this issue Mar 23, 2024 · 4 comments

Comments

@wikiped
Copy link

wikiped commented Mar 23, 2024

There is a similar issue, which is closed without, as it appears, any fix (with v0.9.1 being actual).

Expected behaviour is outlined in examples of python-calamine for an option skip_empty_area:

from python_calamine import CalamineWorkbook

workbook = CalamineWorkbook.from_path("file.xlsx").get_sheet_by_name("Sheet1").to_python(skip_empty_area=False)
# [
# [",  ",  ",  ",  ",  ",  "],
# ["1",  "2",  "3",  "4",  "5",  "6",  "7"],
# ["1",  "2",  "3",  "4",  "5",  "6",  "7"],
# ["1",  "2",  "3",  "4",  "5",  "6",  "7"],
# ]

This automatic behavior is kind of surprising when dealing with files with empty parts at the beginning, as the whole rows calculations get confusing. i.e. for header_row you have to count rows as they appear (i.e. including empty rows), but for skip_rows you have to count as if there are no empty rows, which is clearly not the most user-friendly approach.

Please consider adding an option/parameter to disable default behavor.
Thank you!

@PrettyWood
Copy link
Member

PrettyWood commented Mar 24, 2024

header_row is the row chosen for the header so of course all rows are taken into account.
Once this is set, skip_rows is just the number of rows you want to skip for pagination for example. If you needed to add the header row every time, I reckon this would make the API harder to use.

That being said we could add a parameter similar to skip_empty_area.
Just to know what is the use case?

@wikiped
Copy link
Author

wikiped commented Mar 24, 2024

what is the use case?

In an ETL pipeline incoming Excel files use arbitrary layout (inluding multi-rows headers and/or empty rows between header and the data). The task is to process the files using predefined specs for first_header_row, last_header_row, first_data_row - set by the user once. The user is only dealing with visible Excel row numbering and is not aware of the internals of how the actual processing happens. So if the user sees that the header starts at row 2 and ends at row 2 and data starts at row 4 - the resulting dataframe should start from row 4. currently it does not. Because skip_rows=1 (based on previous settings) is making dataframe to start from row 5.

@PrettyWood
Copy link
Member

This requires changes on calamine side. I will try to open a PR soon. Since 0.11 has some nice improvements, we don't want to postpone it even more for that

@severinh
Copy link

severinh commented Jul 19, 2024

I'm afraid I'm facing the same issue.

Our systems are currently using python-calamine with .to_python(skip_empty_area=False).

Whats's the use case: In one of our systems, users specified a row index in their Excel sheet that is of special interest. But we cannot just start reading from that row (with header_row). We need the data of the entire sheet. And that sheet may contain empty rows at the top. By silently skipping empty rows at the top of the sheet (and not knowing how many were skipped), the sheet we would get out of fastexcel would not line up with the row configuration from the user, and we could not locate that special row anymore. I don't like the system for its fragility - but for now we're stuck with it. :)

Hence, for moving to fastexcel, we would need the equivalent of that skip_empty_area=False option in python-calamine.

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