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
dynamically resize the table matrix on set_value #233
Conversation
Yep, pyexcel has not explored random access, which restrict use cases like yours. I recommend you have a closer look at paste function, which I explicitly forbid it exceeding the original dimension. You may find a way to relax it. |
i see that, the restriction is in _set_row_at. so, given that there is an expensive call to uniform() in that function too, is there something wrong with my approach or is it just unintended behavior to allow random inserts? |
I could be biased. It seems uniform function will also grow the two dimensional array, plus the original intent. Could the growth function be separated? As to other side effect, I don’t think so. Current constraints were kept because personally I do not have a strong use case to support it. I wrote a lot of useless functions in pyexcel in the beginning. So, as long as your change would pass the existing unit tests, your PR with unit tests for new code are good enough to be released. |
‘make format’ will do automatically code formatting. |
Codecov Report
@@ Coverage Diff @@
## dev #233 +/- ##
==========================================
- Coverage 98.35% 98.32% -0.03%
==========================================
Files 103 104 +1
Lines 6732 6763 +31
==========================================
+ Hits 6621 6650 +29
- Misses 111 113 +2
Continue to review full report at Codecov.
|
Good, it means there is no regression caused. Please write the unit tests which will protect your use case in the future:
In the long run, the unit tests you contributed will live longer than the code you wrote. In essence, your use case will be kept alive as long as your unit tests will be kept. The non-test codes you contributed are mortal. |
thx @chfw ! I will prepare this pr right and add tests. |
As a side topic, TDD would advise you to write unit test first then write the code. |
sure! I am happy to comply with your rules (even 80char limits) and contribute more, if you are fine with human beings like me having different ways of solving their problems :) Shall i add a howto contribute and missing commands from pr template to ease the path for future contributors? |
You are welcome to contribute more. Regarding contributor guide and PR template, you can find them here: https://github.com/pyexcel/pyexcel-mobans/tree/master/templates. Once your changes is committed there, |
thanks @chfw . i meant to make a guide on tooling / requirements for pre-commit checks... however thats a different story and i think all issues with this pr are resolved. |
Precommit sounds cool. I never had the time to work it out. |
tests/test_sheet_access.py
Outdated
from base import SheetBaseTestcase | ||
|
||
|
||
class SheetAccessTest(SheetBaseTestcase): |
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 you come from OOP background!
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.
Every time I make a class, I will ask myself: will I use any of the OOP features? If answer is NO, I will not use use classes.
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.
Please do not take it as criticism. Developers have their own view. I would like to hear more from you. That is an exchange.
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.
well, i'm not coming from the java world if that's what you mean... ;)
If you have a hard opinion about it i can revert it to pure functions, but especially in unit tests i liked the idea of having a common base class. For grouping as well as for the common setUp and tearDown functions. I saw you were using them quite frequently too...
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.
Yes, I am opinionated when it comes to Java. “Thinking in Java” book had a a whole chapter: everything is object, hence Java developers cannot forget it when they write Python code.
Surely if you use OOP features, then a class will make more sense. What I am object to make a class for the sake of OOP.
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.
sure.
i added another test to raise the coverage, and make the point of having a class more clear ;)
Don't know why codecov still fails. any idea?
….rst, contributors.rst
well. shame on me. the regex seems to be (Test*) fixed that. now theres a ton of commits but you can squash them if you want.. |
self.paste((row, column), [[new_value]]) | ||
else: | ||
if not fit: | ||
width, array = uniform(self.__array, row+1, column+1) |
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.
I think here, it is supposed that row > number of rows and column > number of rows.
what happens if:
- row < number of rows but column > number of rows
- row > number of rows but column < number of rows
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.
it is good to add two tests to test above two conditions
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.
i added those two edge cases as test, but to me it looks pretty clear:
fit = row < row_num and column < column_num
row < row_num, column > column_num => True and False => fit = false
row > row_num, column < coulmn_num => False and True => fit = false
the PR looks good now. Let's see about the 'extra miles' if you could extend the unit tests a bit. |
I will conform to pr checklist later.
here is a use case:
that leads to an index error.
I think it is a valid use case to set arbitrary cells at random positions?
This pr adds arguments to uniform so we can make an array of min_width and min_height
With your PR, here is a check list:
make format
been run?