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

Solution for checking system OS to accurately printing polars DataFrame format. #5941

Closed
2 tasks done
arturdaraujo opened this issue Dec 29, 2022 · 2 comments
Closed
2 tasks done
Labels
bug Something isn't working python Related to Python Polars

Comments

@arturdaraujo
Copy link

arturdaraujo commented Dec 29, 2022

Polars version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of Polars.

Issue description

The wrong default table format for Linux. Set pl.Config.set_tbl_formatting when importing.

Solution:

A general solution for differentiating the os systems is here:

if sys.platform.startswith("linux"):  # could be "linux", "linux2", "linux3", ...
    # linux
elif sys.platform == "darwin":
    # MAC OS X
elif os.name == "nt":
    # Windows, Cygwin, etc. (either 32-bit or 64-bit)

I suggest the code below be implemented every time when printing a data frame or just one time when importing Polars (which would be ideal, it would run only once. But any solution is okay since the runtime is minimal). I'm also reproducing the time to run this code to prove that the time is negligible. The packages are all from Python Standard Library (built-in packages).

Here is what I suggest:

if sys.platform.startswith("linux"):  # could be "linux", "linux2", "linux3", ...
    pl.Config.set_ascii_tables(True)  

I also mention similar problem in #5942 for changing the default format.

References:

Reproducible example

import polars as pl
from datetime import datetime

df_stock = pl.DataFrame(
    {
        "date_time": pl.date_range(
            low=datetime(2000, 1, 1, 0, 0),
            high=datetime(2023, 1, 1, 0, 0),
            interval="1d",
        ).shuffle(seed=0)
    }
)
print(df_stock)

shape: (8402, 1)
┌─────────────────────╌╌╌╌┐
│ date_time           │
│ ---                     │
│ datetime[μs]        │
╞═════════════════════╌╌╌╌╡
│ 2008-05-13 00:00:00 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 2000-11-24 00:00:00 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 2005-08-09 00:00:00 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 2009-09-04 00:00:00 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ ...                 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 2010-06-30 00:00:00 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 2010-08-18 00:00:00 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 2010-02-06 00:00:00 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 2010-04-16 00:00:00 │
└─────────────────────╌╌╌╌┘

Expected behavior

print(df_stock)
shape: (8402, 1)
+---------------------+
| date_time           |
| ---                 |
| datetime[μs]        |
+=====================+
| 2008-05-13 00:00:00 |
|---------------------|
| 2000-11-24 00:00:00 |
|---------------------|
| 2005-08-09 00:00:00 |
|---------------------|
| 2009-09-04 00:00:00 |
|---------------------|
| ...                 |
|---------------------|
| 2010-06-30 00:00:00 |
|---------------------|
| 2010-08-18 00:00:00 |
|---------------------|
| 2010-02-06 00:00:00 |
|---------------------|
| 2010-04-16 00:00:00 |
+---------------------+

Installed versions

---Version info---
Polars: 0.15.6
Index type: UInt32
Platform: Linux-5.15.79.1-microsoft-standard-WSL2-x86_64-with-glibc2.35
Python: 3.10.8 | packaged by conda-forge | (main, Nov 22 2022, 08:26:04) [GCC 10.4.0]
---Optional dependencies---
pyarrow: 7.0.0
pandas: 1.5.2
numpy: 1.23.5
fsspec: 2022.11.0
connectorx: <not installed>
xlsx2csv: <not installed>
matplotlib: 3.6.2
@arturdaraujo arturdaraujo added bug Something isn't working python Related to Python Polars labels Dec 29, 2022
@arturdaraujo arturdaraujo changed the title Solution for checking system OS to accurately printing polars DataFrame. Solution for checking system OS to accurately printing polars DataFrame format. Dec 29, 2022
@alexander-beedie
Copy link
Collaborator

@arturdaraujo: FYI - can close this now #5942 is merged (and you noticed that it was WSL causing font-spacing issues).

Happy New Year :)

@arturdaraujo
Copy link
Author

Thanks! Happy New Year :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working python Related to Python Polars
Projects
None yet
Development

No branches or pull requests

2 participants