bug fix related #5479 #6047

Merged
merged 12 commits into from Mar 7, 2016

Conversation

Projects
None yet
4 participants
Contributor

ryanbelt commented Feb 22, 2016

Table: auto_set_column_width not working #5479

As before, it append the whole parameter(col) into the _autoColumns even col is a list object.
at table.py line 490 inside function _update_position

for col in self._autoColumns:
      self._auto_set_column_width(col, renderer)

_auto_set_column_width are not able to manipulate with the index number as list rather then int passed from line490.

So, I decide to append number to _autoColumns as usual if and only if the parameter is integer. If it is a list, we will append each integer inside the parameter into _autoColumns

mdboom added the needs_review label Feb 22, 2016

@tacaswell tacaswell commented on an outdated diff Feb 22, 2016

lib/matplotlib/table.py
@@ -410,7 +410,13 @@ def _do_cell_alignment(self):
def auto_set_column_width(self, col):
- self._autoColumns.append(col)
+ # col is a list of column index
+ if isinstance(col, list):
@tacaswell

tacaswell Feb 22, 2016

Owner

This is probably better to do as

try:
    self._autoColumns.extend(cell)
except CORRECT_EXCEPTION:
    self._autoColumns.append(col)
@ryanbelt ryanbelt raising error,rather then check type
32c5553
Contributor

ryanbelt commented Feb 23, 2016

I have change the format from type checking to exception checking.
This would allow not only list obj as the parameter, but also any kinds of iterable object such tuple etc.

table.auto_set_column_width(-1) # Default input
table.auto_set_column_width([-1,0,1]) # List input
table.auto_set_column_width((-1,0,1)) # Tuple input

@tacaswell tacaswell commented on an outdated diff Feb 23, 2016

lib/matplotlib/table.py
@@ -410,7 +410,14 @@ def _do_cell_alignment(self):
def auto_set_column_width(self, col):
- self._autoColumns.append(col)
+ # check for col possibility on iteration
+ try:
+ iter(col)
+ except (TypeError, AttributeError):
+ self._autoColumns.append(col)
+ else:
+ for cell in col:
@tacaswell

tacaswell Feb 23, 2016

Owner

This indentation is funny and you can use extend.

ryanbelt added some commits Feb 23, 2016

@ryanbelt ryanbelt minor fix on indentation
c706d5c
@ryanbelt ryanbelt revert to no indentation fix 54eec61
@ryanbelt ryanbelt fix indention to 4 space, but not tap 1b3f49c
@ryanbelt ryanbelt fix indention to 4 space, but not tap
4e166e2

tacaswell referenced this pull request Feb 25, 2016

Closed

fixes #5479 #6059

Contributor

ryanbelt commented Feb 26, 2016

I have just seen the comment from #6059. I am going to add the specific test case for this PR.

ryanbelt added some commits Feb 26, 2016

@ryanbelt ryanbelt added test for bug#5479 auto column
c163397
@ryanbelt ryanbelt pep8 new line at last
9db6a59
@ryanbelt ryanbelt fix pep8 miss space after comma
05d86b5
@ryanbelt ryanbelt pep8 line gt 80 fix
1898bec
@ryanbelt ryanbelt comment fix, rerun online testing
413f60f
Contributor

ryanbelt commented Feb 27, 2016

@tacaswell ,
Test case for this specific bug has been added. Bascially testing every single column be able to auto_width. By using List, Tuple and single integer as input. I think those are the main issue on this bug.
Thank you

Contributor

dashed commented Feb 27, 2016

Strings are also iterable. Should that be also supported?

tacaswell added this to the 2.1 (next point release) milestone Feb 28, 2016

Contributor

ryanbelt commented Feb 28, 2016

@dashed , inside the _auto_set_column_width. if the object inside the _autoColumns is not an integer(index), It will not able to do the width adjustment and remain as default width (will causing content go out the box). So, it will not crash the program. It just skip all those string object until next integer found or stop at the end of the _autoColumns.

Contributor

dashed commented Feb 28, 2016

@ryanbelt Ah ok. Then should there be a test case for the behaviour you've just described?

@ryanbelt ryanbelt non integer interable test case
8a3349f
Contributor

ryanbelt commented Feb 28, 2016

@dashed , thank you for the tips. Unexpected test case for iterable input as string has been added for this bug.

@dashed dashed commented on the diff Feb 28, 2016

lib/matplotlib/table.py
@@ -410,7 +410,15 @@ def _do_cell_alignment(self):
def auto_set_column_width(self, col):
- self._autoColumns.append(col)
+ # check for col possibility on iteration
@dashed

dashed Feb 28, 2016

Contributor

This might be worded in another way. Suggestion:

If col is iterable, concatenate to self._autoColumns. Otherwise, append it to self._autoColumns.

Contributor

dashed commented Feb 28, 2016

@ryanbelt Awesome. 👍 Unfortunately you beat us to the punch on this PR for d01. But I'll throw some suggestions your way for this PR 😄 .

@tacaswell tacaswell added a commit that referenced this pull request Mar 7, 2016

@tacaswell tacaswell Merge pull request #6047 from ryanbelt/master
FIX: table auto_column_width

fix #5479
963e51d

@tacaswell tacaswell merged commit 963e51d into matplotlib:master Mar 7, 2016

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

tacaswell removed the needs_review label Mar 7, 2016

Owner

tacaswell commented Mar 7, 2016

Thanks!

Would one of you @dashed or @ryanbelt be willing to write a docstring for auto_set_column_width?

Contributor

dashed commented Mar 7, 2016

I'll leave that for @ryanbelt 😄

Contributor

ryanbelt commented Mar 7, 2016

        """Given column indexs in either List, Tuple or int. Will be able to
        autonatically set the columns into optimal sizes.
        """

@tacaswell ,
How should I added into the table.py since this pull request is closed?
Thank you.

Owner

tacaswell commented Mar 7, 2016

@ryanbelt Make a new pull request. They are (more-or-less) free and the smaller the change, the easier it is to review.

Could you also explain the meaning of the values that are expected to be passed in?

ryanbelt referenced this pull request Mar 7, 2016

Merged

docstring added #6123

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