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

[feature] Add 'expand_table' feature #1475

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

lavigne958
Copy link
Collaborator

Add a new feature that allows a user to expand a cell range
into a table.

the expand will look for the right most cell with adjacent value.
the expand will look for the bottom most cell with adjacent value.
the expand will table down from top left celle range to bottom right
value.

closes #1414

Signed-off-by: Alexandre Lavigne [email protected]

@lavigne958 lavigne958 self-assigned this Jun 2, 2024
@lavigne958 lavigne958 requested a review from alifeee June 2, 2024 22:39
Add a new feature that allows a user to expand a cell range
into a table.

the expand will look for the right most cell with adjacent value.
the expand will look for the bottom most cell with adjacent value.
the expand will table down from top left celle range to bottom right
value.

closes #1414

Signed-off-by: Alexandre Lavigne <[email protected]>
Copy link
Collaborator

@alifeee alifeee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a nice self-contained change. good work here :)

I think we need more tests, as I foresee a lot of edge cases, and it would be good to catch those before the feature is in gspread.

For example, what is the expectation for expanding this table from the top left?

1 1 - 1
1 1 1 1
- - 1 -
1 1 1 1

This is not clear to me. Also the internal (private) utils expanding functions are unclear what they do.

As well, we should have a utils test and a worksheet test. Currently there is only utils

gspread/utils.py Outdated Show resolved Hide resolved
gspread/utils.py Outdated Show resolved Hide resolved
gspread/utils.py Outdated Show resolved Hide resolved
gspread/utils.py Outdated Show resolved Hide resolved
gspread/worksheet.py Outdated Show resolved Hide resolved
gspread/worksheet.py Outdated Show resolved Hide resolved
gspread/worksheet.py Show resolved Hide resolved
gspread/worksheet.py Outdated Show resolved Hide resolved
gspread/worksheet.py Outdated Show resolved Hide resolved
tests/utils_test.py Outdated Show resolved Hide resolved
@lavigne958
Copy link
Collaborator Author

lavigne958 commented Jun 13, 2024

this is a nice self-contained change. good work here :)

I think we need more tests, as I foresee a lot of edge cases, and it would be good to catch those before the feature is in gspread.

I thought about it and I thought:
we need to put limits to what we want to handle here:
Do we want to handle empty cells in the middle of the table ?
Do we want to handle cases when the given table is not square ?

For example, what is the expectation for expanding this table from the top left?

1	1	-	1
1	1	1	1
-	-	1	-
1	1	1	1

I would expect something like:

  • assuming the first row in the above example is data and part of the table, top left 1 is A1 coordinate:

| 1 | 1 |
| 1 | 1 |

  • assuming the first row are headers we don't take them:

| 1 | 1 |

This is not clear to me. Also the internal (private) utils expanding functions are unclear what they do.

As well, we should have a utils test and a worksheet test. Currently there is only utils

so far the method in Worksheet class does nothing particular, but I'll add test just in case, so we have a real test with data we get.

@alifeee
Copy link
Collaborator

alifeee commented Jun 18, 2024

I thought about it and I thought:
we need to put limits to what we want to handle here:
Do we want to handle empty cells in the middle of the table ?
Do we want to handle cases when the given table is not square ?

I think a reasonable implementation is "the same as what happens when you CTRL+RIGHT and CTRL+DOWN", i.e., to stop just before empty cells.

As for whether that is what other people will expect... that's another question... if people think it should work a certain way, they may think there is a bug... which is why very clear docstrings are good

assuming the first row are headers we don't take them:
| 1 | 1 |

wait, huh? why are we ignoring the headers? the function should just return a List[List]] with all items in the table starting from the called cell?

I will look back at the code now :)

Copy link
Collaborator

@alifeee alifeee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are doing good work on this change :)

I have left some comments. I am a little worried that a new feature will result in something we do not consider, causing errors. But I think we will be ok now.

thanks!!!

gspread/utils.py Outdated Show resolved Hide resolved
gspread/utils.py Outdated Show resolved Hide resolved
gspread/utils.py Outdated Show resolved Hide resolved
gspread/utils.py Show resolved Hide resolved
gspread/worksheet.py Outdated Show resolved Hide resolved
gspread/worksheet.py Outdated Show resolved Hide resolved
gspread/worksheet.py Outdated Show resolved Hide resolved
@alifeee alifeee added this to the 6.2.0 milestone Jun 29, 2024
@alifeee
Copy link
Collaborator

alifeee commented Jun 29, 2024

I have added some new tests. In particular, they are "what should happen" tests. They are:

1 - missing header item

        values = [
            ["A1", "", "C1", ""],
            ["A2", "B2", "C2", ""],
            ["A3", "B3", "C3", ""],
            ["", "", "", ""],
        ]
        expected_table = [
            ["A1"],
            ["A2"],
            ["A3"],
        ]

2 - missing initial cell

        values = [
            ["", "B1", "C1", ""],
            ["A2", "B2", "C2", ""],
            ["A3", "B3", "C3", ""],
            ["", "", "", ""],
        ]
        expected_table = [
            ["", "B1", "C1"],
            ["A2", "B2", "C2"],
            ["A3", "B3", "C3"],
        ]

3 - missing first column item

        values = [
            ["A1", "B1", "C1", ""],
            ["", "B2", "C2", ""],
            ["A3", "B3", "C3", ""],
            ["", "", "", ""],
        ]
        expected_table = [
            ["A1", "B1", "C1"],
            ["", "B2", "C2"],
            ["A3", "B3", "C3"],
        ]

4 - missing last column item

        values = [
            ["A1", "B1", "C1", ""],
            ["A2", "B2", "", ""],
            ["A3", "B3", "C3", ""],
            ["", "", "", ""],
        ]
        expected_table = [
            ["A1", "B1", "C1"],
        ]

Conc.

Are these what you expect? Personally I might want case 4 to end up in the entire table, as I reckon I am more likely to have a full first column, and empty gaps in the final column.

However, if I use the CTRL+RIGHT and CTRL+DOWN shortcuts in most spreadsheet software, then the tables above are the same. So I am happy with the behaviour above.

I am ready to merge this 👍. However, we should also add it to the list of examples and documentation somewhere.

Copy link
Collaborator

@alifeee alifeee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include in examples docs. otherwise approve :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cell.expand('table') feature requests
2 participants