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

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

Closed
sidkang opened this issue Apr 20, 2020 · 9 comments
Closed

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

sidkang opened this issue Apr 20, 2020 · 9 comments

Comments

@sidkang
Copy link

sidkang commented Apr 20, 2020

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

@dricetar
Copy link

same issue

@jquast
Copy link

jquast commented May 30, 2020

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.

@jquast
Copy link

jquast commented May 31, 2020

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

@gfrlv
Copy link
Contributor

gfrlv commented May 31, 2020

@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

@sidkang
Copy link
Author

sidkang commented Jun 1, 2020

@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

@jquast
Copy link

jquast commented Jun 2, 2020

@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

@sidkang
Copy link
Author

sidkang commented Jun 2, 2020

@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

@jquast
Copy link

jquast commented Jun 2, 2020

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

@astanin
Copy link
Owner

astanin commented Feb 17, 2021

This issue seems to be fixed now:

image

This was fixed in pull request #58

@astanin astanin closed this as completed Feb 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants