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

special character width problem #46

Closed
playgithub opened this issue Oct 21, 2020 · 6 comments
Closed

special character width problem #46

playgithub opened this issue Oct 21, 2020 · 6 comments

Comments

@playgithub
Copy link

image

import pandas as pd
from tabulate import tabulate
from io import StringIO
import wcwidth


csv_str = ''',0,1,2
0,a)  将净利润调节为经营活动现金流量,,
1,,2019 年度,2018 年度
2,净利润,"63,205,243","55,350,200"
3,加:资产减值损失,"(73,370)","10,465,899"
4,信用减值损失,"3,611,595",—
5,固定资产折旧,"6,543,253","6,530,713"
6,投资性房地产折旧,"1,718,108","1,514,560"
7,无形资产摊销,"447,821","440,444"
8,长期待摊费用摊销,"338,210","189,875"
9,处置固定资产、无形资产和其他长,,
10,期资产的收益,"(568,141)","(175,112)"
11,财务费用,"10,179,757","12,568,535"
12,公允价值变动损失,"484,752","368,343"
13,投资收益,"(4,212,538)","(5,646,311)"
14,递延所得税资产的增加,"(3,083,170)","(2,511,075)"
15,递延所得税负债的增加/(减少),"107,125","(644,386)"
16,存货的增加,"(70,420,830)","(96,125,732)"
17,受限资金的(增加)/减少,"(1,387,681)","280,759"
18,经营性应收项目的增加,"(125,133,902)","(108,365,569)"
19,经营性应付项目的增加,"83,217,173","135,881,219"
'''

csv_io = StringIO(csv_str)

df = pd.read_csv(csv_io, index_col=0)

print(df)

df_tabulated = tabulate(df, headers='keys', tablefmt='psql', showindex=False)

print(df_tabulated)
@jquast
Copy link
Owner

jquast commented Oct 23, 2020

does not reproduce for me, please tell me:

  • version of tabulate, and
  • version of wcwidth

verify:

>>> import wcwidth; wcwidth.wcswidth('信用减值损失')
12

Screen Shot 2020-10-23 at 11 08 21 AM

@playgithub
Copy link
Author

playgithub commented Oct 23, 2020

version info:

  • python 3.8.5
  • tabulate 0.8.7
  • wcwidth 0.2.5

test:

>>> import wcwidth; wcwidth.wcswidth('信用减值损失')
12

the problem seems here:

>>> import wcwidth; wcwidth.wcswidth('—')
1

it should be 2

@jquast
Copy link
Owner

jquast commented Oct 31, 2020

Thanks for clarifying, I’ll look into it maybe during it between holidays, a bit busy but any PR always welcome thanks for the report !!!

@playgithub
Copy link
Author

Just more evidence
image

@playgithub
Copy link
Author

playgithub commented Nov 18, 2020

Above are tested in Visual Studio 2019 on Windows.

Tested in vscode on Linux, no problem.

Tested in pycharm on Linux
image

@playgithub
Copy link
Author

playgithub commented Nov 18, 2020

When changed to a specific font, Inconsolata, it aligned perfectly.
The problem might be caused by font, for "—", the width might be 1 or 2 that depends on the font.

BTW, pycharm output font is the the same as editor font

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

2 participants