question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow whitespace alignment of tables of numbers?

See original GitHub issue

For example, np.arange(0, 120).reshape(12, 10) is formatted by NumPy as

array([[  0,   1,   2,   3,   4,   5,   6,   7,   8,   9],
       [ 10,  11,  12,  13,  14,  15,  16,  17,  18,  19],
       [ 20,  21,  22,  23,  24,  25,  26,  27,  28,  29],
       [ 30,  31,  32,  33,  34,  35,  36,  37,  38,  39],
       [ 40,  41,  42,  43,  44,  45,  46,  47,  48,  49],
       [ 50,  51,  52,  53,  54,  55,  56,  57,  58,  59],
       [ 60,  61,  62,  63,  64,  65,  66,  67,  68,  69],
       [ 70,  71,  72,  73,  74,  75,  76,  77,  78,  79],
       [ 80,  81,  82,  83,  84,  85,  86,  87,  88,  89],
       [ 90,  91,  92,  93,  94,  95,  96,  97,  98,  99],
       [100, 101, 102, 103, 104, 105, 106, 107, 108, 109],
       [110, 111, 112, 113, 114, 115, 116, 117, 118, 119]])

but the linters used in unit testing reject tables of numbers like this because of rules like these:

  • E201 whitespace after ‘[’
  • E202 whitespace before ‘]’
  • E221 multiple spaces before operator
  • E222 multiple spaces after operator
  • E241 multiple spaces after ‘,’

and require changing to the less readable

array([[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
       [10, 11, 12, 13, 14, 15, 16, 17, 18, 19],
       [20, 21, 22, 23, 24, 25, 26, 27, 28, 29],
       [30, 31, 32, 33, 34, 35, 36, 37, 38, 39],
       [40, 41, 42, 43, 44, 45, 46, 47, 48, 49],
       [50, 51, 52, 53, 54, 55, 56, 57, 58, 59],
       [60, 61, 62, 63, 64, 65, 66, 67, 68, 69],
       [70, 71, 72, 73, 74, 75, 76, 77, 78, 79],
       [80, 81, 82, 83, 84, 85, 86, 87, 88, 89],
       [90, 91, 92, 93, 94, 95, 96, 97, 98, 99],
       [100, 101, 102, 103, 104, 105, 106, 107, 108, 109],
       [110, 111, 112, 113, 114, 115, 116, 117, 118, 119]])

I’ve listed a bunch of other examples here: https://github.com/PyCQA/pycodestyle/issues/289#issuecomment-517937832

I think this is a misapplication of PEP8, and this type of formatting should be allowed, but turning off these error codes completely would be bad, since they are much broader than this, and are correct for one-line lists, etc.

Ideally the rules for tables of data would be changed in PEP8 and pycodestyle, so it trickles down to everything that depends on them, but my attempts at requesting changes to pycodestyle and PEP8 were rejected: https://github.com/PyCQA/pycodestyle/issues/289 https://github.com/python/peps/issues/1428 If you know of a better place to lobby for this, we could try that.

Otherwise, it seems all we could do is implement plugins to flake8 to prevent this from happening? Maybe there are other workarounds.

See also https://github.com/spyder-ide/spyder/issues/9955 and this PR failure and this PR failure.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
larsonercommented, Jul 9, 2020
1reaction
WarrenWeckessercommented, Jun 14, 2020

I also made a request to pycodestyle in https://github.com/PyCQA/pycodestyle/issues/924, before I saw @endolith’s earlier issue and comments.

I agree that we should be able to create aligned arrays of data without our style checker complaining about whitespace issues. I would have been OK (if not completely happy) with appending # noqa at the end of each line that is part of such an array, but that doesn’t disable pycodestyle’s whitespace checker.

With flake8, specific rules can be turned off, so one could use, say, # noqa: E201, E241. I haven’t looked into what is involved in creating a flake8 plugin–maybe a plugin could be written that would require even less inline markup for this. Even without a plugin, I can support switching to flake8 in our CI style checks so we can use the # noqa markup with arrays of numbers.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Align text in Numbers on Mac - Apple Support
In the Format sidebar, click the Text tab. Click the Style button near the top of the sidebar, then click the alignment buttons...
Read more >
Number alignment and spacing in tables with parentheses ...
The rows X to Z and Fstat are not correctly centered (I have tried table-number-alignment=center and it did not work). In addition, each...
Read more >
Align text - Numbers Help
Align text and adjust spacing You can adjust text in a text box, shape, table cell, row, or column so that it's aligned...
Read more >
The Path to Beautiful Tables, Part III: Working With Numbers
There's a workaround for this. If you do need to hang a built fraction to the right of otherwise decimal-aligned numerals, add a...
Read more >
Problem: Cell alignment in a table - Microsoft Community
I am having a puzzling problem in a table. Using Cell Alignment I want to line up a line of text and a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found