Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1900372

Browse files
committed
FIX: compute str column width
The division was always returning 1, use length of first element instead.
1 parent 966f50b commit 1900372

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

lib/matplotlib/mlab.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3188,9 +3188,7 @@ def get_justify(colname, column, precision):
31883188
ntype = column.dtype
31893189

31903190
if np.issubdtype(ntype, str) or np.issubdtype(ntype, bytes):
3191-
# The division below handles unicode stored in array, which could
3192-
# have 4 bytes per char
3193-
length = max(len(colname), column.itemsize // column[0].itemsize)
3191+
length = max(len(colname), len(column[0]))
31943192
return 0, length+padding, "%s" # left justify
31953193

31963194
if np.issubdtype(ntype, np.int):

lib/matplotlib/tests/test_mlab.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,9 @@ def test_csv2txt_basic(self):
403403
(str('y'), np.int8),
404404
(str('s'), str, 3),
405405
(str('s2'), str, 4)]))
406-
truth = (' x y s s2\n'
407-
' 1.000 2 foo bing \n'
408-
' 2.000 3 bar blah ').splitlines()
406+
truth = (' x y s s2\n'
407+
' 1.000 2 foo bing \n'
408+
' 2.000 3 bar blah ').splitlines()
409409
assert_equal(mlab.rec2txt(a).splitlines(), truth)
410410

411411

0 commit comments

Comments
 (0)