-
Notifications
You must be signed in to change notification settings - Fork 949
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
Conversation
3df98d7
to
93ffc1e
Compare
There was a problem hiding this 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
I thought about it and I thought:
I would expect something like:
| 1 | 1 |
| 1 | 1 |
so far the method in |
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
wait, huh? why are we ignoring the headers? the function should just return a I will look back at the code now :) |
There was a problem hiding this 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!!!
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 I am ready to merge this 👍. However, we should also add it to the list of examples and documentation somewhere. |
There was a problem hiding this 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 :)
thank you for the extra tests ! ⭐ I am a bit confused with the tests and what I see when I try it online using keyboard controls 😞
so for 1., 3. and 4. I agree with your tests and the result is what I would expect. |
I have made this sheet https://docs.google.com/spreadsheets/d/1huMwgagFCGTMVBf5mONk_W74-qHZUnpASHuVHnU6Hsk/edit?usp=sharing I think maybe we do not "do the same as CTRL+arrow keys does", as this is confusing. I think we find another rule to follow (perhaps "the same as what xlwings does") |
Hey thanks for the working sample ! I completely agree with you some behaviors are completely unexpected 😞 To me we should go for what feels logical to us, which seems to be what is described in the
does that sounds good to you ? 🤔 |
I believe my preference is to "find a table" by "complete row 1 and column 1" so, to look at these
...and if they are empty, terminate the table there. I have updated the tests to do this (please have a look at the tests to see if you agree). What do you think? |
I agree with this, the only detail would be: look down first then right. |
I did quite a big rework on the iteration functions. all tests now pass, though the tests already here needed to be adjusted:
it works as expected, like xlwings. |
why does xlwings use the left column and bottom row? it makes more sense to me that one would desire the top row? |
I know, that's what I did first, but we agreed on making it ISO with xlwings. I don't mind changing it, I just want us to agree on one implementation. |
I don't think that's how xlwings works. I think xlwings uses the top row and left column. See here for their implementation: https://github.com/xlwings/xlwings/blob/a159cc9cb7ef5f168ad0d902934404bce4a76386/xlwings/expansion.py#L31-L52 (I can't parse it with my mind fully but it looks to use the top row, not the bottom) see also this comment: xlwings/xlwings#557 (comment) |
you're right ! this provides the right and down boundaries then the rest is just to extract the matrix from here. I'll update the code, expect potentially a big code change/refactoring then ! |
Update
I hope this covers any wrong inputs, the expected behavior from all (most?) users. I'll rebase my branch before merge |
this looks all good to me! only final thing is that I would expect a table like
to expand properly, whereas it seems you suggest with
that it would return as an empty list |
Yes to me this function will return the table starting from the given coordinates. The starting cell is part of the resulting table. so if the starting cell is indeed empty then the table will be empty. So far that seems to be the last key point where we can't find seems to be best. Should we just put it as an option like "ignore empty starting cell" ? Of true then we follow your choice of false we follow mine. This way the user decides the behavior. What do you think? |
apologies for the delay while I think a special case for a blank row 0 column 0 would be nice (e.g., for a labelled adjacency matrix), it is probably not worth the complication (e.g., if the row 0 column 0 is empty, but also row 1 column 0 and row 0 column 1 are empty, it should return Thus, I think we return However, there should be a test to validate this behaviour. After that, I think this is ready to merge! |
I added a new commit with a test to validate the top left cell empty scenario. I added an extra test too in the basic test for find_table to check when we reach the end of the list and the end of the matrix. just in case. |
this is good with me! with the amount of work spent on a new feature... let's put reference to it in all the relevant places in the documentation :) |
great call, it's done ✔️ |
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]>
Signed-off-by: Alexandre Lavigne <[email protected]>
532f7aa
to
858d77d
Compare
before merging I rebased the whole thing in order to solve conflicts of any. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems good to me ! I am assuming you have manually tested the worksheet function (as there is only a utils function)
I hope you have had fun with this one ;]
I say we can merge this.
Signed-off-by: Alexandre Lavigne <[email protected]>
yes I did 😉 it works like a charm. I just pushed a quick fix on the docstring to make the link to the raised exception work in the documentation. |
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]