Skip to content

Seems a bug for the layout for the Chinese Character #52

Closed

Description

@sidkang

With Chinese characters in the DataFrame, it seems the tabulate package cannot identify the correct width.

import pandas as pd
import tabulate

print(tabulate.__version__)
print(tabulate.WIDE_CHARS_MODE)
df = pd.DataFrame({
    '序号':['001', '021', '032'],
    '类型': ['汽车TESLA', '飞机737-MAX', 'TRAIN'],
    '备注': ['特殊', '一长串字符', '字符+1020']
})
print(tabulate.tabulate(df, tablefmt="github"))

The Output is :
0.8.7
True
|---|-----|-------------|------------|
| 0 | 001 | 汽车TESLA | 特殊 |
| 1 | 021 | 飞机737-MAX | 一长串字符 |
| 2 | 032 | TRAIN | 字符+1020 |
Screen Shot 2020-04-21 at 12 58 57 AM

Activity

  1. dricetar commented on Apr 27, 2020

    @dricetar

    same issue

  2. jquast commented on May 30, 2020

    @jquast
    Contributor

    You can assign this issue to me, I believe I am working on a solution.

    The problem is due to which version of Unicode is used by wcwidth, may be different from the version supported by your Terminal Emulator. The next version of wcwidth will support all versions of Unicode, and the version used by wcwidth (and tabulate) will be selected by an environment variable.

    And so the solution is to only select the correct version. I am also working on a CLI utility, wcwidth-detect, which will automatically determine it.

  3. jquast commented on May 31, 2020

    @jquast
    Contributor

    I thought this was a unicode version issue, which I am working on a good solution for. But, there is no issue for me to reproduce here, at least on a Mac, using the version of wcwidth and tabulate published on pypi. Which is the same versions reported here.

    I have tried iTerm2.app, Terminal.app, and XTerm version 326 on MacOS/XQuartz, pictured here. I will try a few terminal emulators on Linux next.

    Screen Shot 2020-05-30 at 11 09 57 PM

  4. gfrlv commented on May 31, 2020

    @gfrlv
    Contributor

    @sidkang can you check if you have wcwidth at all installed (pip freeze | grep wcwidth)? It is an optional dependency, so python-tabulate would work happily without it, but the wide character alignment would be off. For example, my output with and without wcwidth:
    image

  5. sidkang commented on Jun 1, 2020

    @sidkang
    Author

    @jquast @dricetar Hi, thanks for your kind reply. Sorry for not test the issue throughly. Just Checked the code in the terminal. Everything works perfectly. The Error only occurred in the Jupiter lab environment. So this could be a Jupiter side issue?
    (My Jupyterlab version is 2.1.3 which is freshly installed.
    image

  6. jquast commented on Jun 2, 2020

    @jquast
    Contributor

    @sidkang: maybe you have multiple python environments, from your Juperlab, are you able to successfully import wcwidth? if not, try

    import subprocess, sys
    subprocess.check_call([sys.executable, "-mpip", "install", "wcwidth"])

    best wishes

  7. sidkang commented on Jun 2, 2020

    @sidkang
    Author

    @sidkang: maybe you have multiple python environments, from your Juperlab, are you able to successfully import wcwidth? if not, try

    import subprocess, sys
    subprocess.check_call([sys.executable, "-mpip", "install", "wcwidth"])

    best wishes

    Just checked the wcwidth package. Seems it is working properly.

    image

  8. jquast commented on Jun 2, 2020

    @jquast
    Contributor

    By the way what happened the first time the issue appeared after installing wcwidth, is you probably needed to restart your Jupyter kernel, you always need to do that when you install/upgrade packages that have already been imported

    there is a kind of refresh button in the GUI for it,

    but anyway it happened naturally when you stepped away for the day :) glad your issue is resolved

    best wishes

  9. astanin commented on Feb 17, 2021

    @astanin
    Owner

    This issue seems to be fixed now:

    image

    This was fixed in pull request #58

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions