Skip to content
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

Dividers don't render correctly at cell intersections with other styles #237

Open
con-f-use opened this issue Apr 10, 2023 · 3 comments
Open
Labels
bug Something isn't working

Comments

@con-f-use
Copy link

con-f-use commented Apr 10, 2023

What did you do?

Set a row divider using an alternate style and print the resulting table.

What did you expect to happen?

$ python t.py
┌─────────┬─────────┬─────────┬─────────┐
│ Field 1 │ Field 2 │ Field 3 │ Field 4 │
├─────────┼─────────┼─────────┼─────────┤
│    11   │    12   │    13   │    14   │
│    21   │    22   │    23   │    24   │
│    31   │    32   │    33   │    34   │
├─────────┼─────────┼─────────┼─────────┤
│    41   │    42   │    43   │    44   │
└─────────┴─────────┴─────────┴─────────┘

What actually happened?

$ python t.py
┌─────────┬─────────┬─────────┬─────────┐
│ Field 1 │ Field 2 │ Field 3 │ Field 4 │
├─────────┼─────────┼─────────┼─────────┤
│    11   │    12   │    13   │    14   │
│    21   │    22   │    23   │    24   │
│    31   │    32   │    33   │    34   │
└─────────┴─────────┴─────────┴─────────┘  <---- should be three-way intersection
│    41   │    42   │    43   │    44   │
└─────────┴─────────┴─────────┴─────────┘

Note the transition into the row below the 2nd divider. The whole 2nd divider should look like the first one (after the "fields" row).

What versions are you using?

  • OS: NixOS 22.11 (Linux)
  • Python: 3.10.10
  • PrettyTable: 3.7.0
# t.py
import prettytable

for style in [
    "DEFAULT", "MSWORD_FRIENDLY", "PLAIN_COLUMNS", "MARKDOWN",
    "ORGMODE", "DOUBLE_BORDER", "SINGLE_BORDER"
]:
    t = prettytable.PrettyTable()
    t.set_style(getattr(prettytable, style))
    t.add_row([11, 12, 13, 14])
    t.add_row([21, 22, 23, 24])
    t.add_row([31, 32, 33, 34])  # also happens with `divider=True`
    t.add_row([41, 42, 43, 44])
    t._dividers[2] = True  # gentle nudge that we need a better non-private API to set dividers after the fact
    print(t, style, "\n\n")     
@con-f-use con-f-use changed the title Deviders don't seem to render correctly Deviders don't seem to render correctly at cell-intersections Apr 10, 2023
@hugovk hugovk changed the title Deviders don't seem to render correctly at cell-intersections Dividers don't seem to render correctly with other styles Apr 10, 2023
@hugovk hugovk changed the title Dividers don't seem to render correctly with other styles Dividers don't seem to render correctly at cell intersections with other styles Apr 10, 2023
@hugovk hugovk added the bug Something isn't working label Apr 10, 2023
@hugovk
Copy link
Member

hugovk commented Apr 10, 2023

To be explicit, here's a reproducer that doesn't use the internal/private _dividers:

import prettytable

t = prettytable.PrettyTable()
t.set_style(prettytable.SINGLE_BORDER)
t.add_row([11,12,13,14])
t.add_row([21,22,23,24])
t.add_row([31,32,33,34], divider=True)
t.add_row([41,42,43,44])
print(t)

Dividers were added in #185, and only tested with the default style.

Here's the results with some other styles (https://github.com/jazzband/prettytable#setting-a-table-style).

DOUBLE_BORDER

Also needs a three-way:

╔═════════╦═════════╦═════════╦═════════╗
║ Field 1 ║ Field 2 ║ Field 3 ║ Field 4 ║
╠═════════╬═════════╬═════════╬═════════╣
║    11   ║    12   ║    13   ║    14   ║
║    21   ║    22   ║    23   ║    24   ║
║    31   ║    32   ║    33   ║    34   ║
╚═════════╩═════════╩═════════╩═════════╝
║    41   ║    42   ║    43   ║    44   ║
╚═════════╩═════════╩═════════╩═════════╝

MARKDOWN

Not sure what to do here:

| Field 1 | Field 2 | Field 3 | Field 4 |
|:-------:|:-------:|:-------:|:-------:|
|    11   |    12   |    13   |    14   |
|    21   |    22   |    23   |    24   |
|    31   |    32   |    33   |    34   |
|:-------:|:-------:|:-------:|:-------:|
|    41   |    42   |    43   |    44   |

Renders like:

Field 1 Field 2 Field 3 Field 4
11 12 13 14
21 22 23 24
31 32 33 34
:-------: :-------: :-------: :-------:
41 42 43 44

ORGMODE

Looks okay?

|---------+---------+---------+---------|
| Field 1 | Field 2 | Field 3 | Field 4 |
|---------+---------+---------+---------|
|    11   |    12   |    13   |    14   |
|    21   |    22   |    23   |    24   |
|    31   |    32   |    33   |    34   |
|---------+---------+---------+---------|
|    41   |    42   |    43   |    44   |
|---------+---------+---------+---------|

PLAIN_COLUMNS

Should maybe omit it here?

Field 1        Field 2        Field 3        Field 4
   11             12             13             14
   21             22             23             24
   31             32             33             34

   41             42             43             44

cc @myheroyuki

@hugovk hugovk changed the title Dividers don't seem to render correctly at cell intersections with other styles Dividers don't render correctly at cell intersections with other styles Apr 10, 2023
@con-f-use
Copy link
Author

con-f-use commented Apr 10, 2023

For plain column's I'd argue that is the expected behavior, because how else would you display a divider. Something like

Field 1        Field 2        Field 3        Field 4
   11             12             13             14
   21             22             23             24
   31             32             33             34
    -              -              -              -            <---- empty line is better in my opinion
   41             42             43             44

might imply "null"-values in that row to some users instead of a separator and a "----------" bar would go against the plain columns style.

In fact, one could argue, that a divider should look a little separate from the field separator, so it might be a feature, not a bug, but then it should be so across all styles. Not arguing for that, in fact, I'd vote against, just putting it out.

@rajarshidcoder
Copy link

this bug can be fixed, by changing one line in the main code (around line number 1781)
lines.append(self.stringify_hrule(options, where="")) #bottom
replace this line of code, it should work

rajarshidcoder added a commit to rajarshidcoder/prettytable that referenced this issue Oct 17, 2023
This bug occurred when we are trying to add a divider and changing the style of it such as "Double border" and it will produce unexpected results.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants