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

feat(python, rust): added new Config formatting option set_tbl_column_data_type_inline, fixed reading of env vars, improved interaction between formatting options #5243

Merged
merged 1 commit into from
Oct 18, 2022

Conversation

alexander-beedie
Copy link
Collaborator

@alexander-beedie alexander-beedie commented Oct 17, 2022

Final piece (probably?) of Config overhaul/enhancement ;)

Updates:

  • Fixed reading boolean environment vars from Rust (was previously just checking if a var was set using is_ok(), but was not actually checking its value, so you couldn't set to "0", you'd have to completely unset it - which doesn't play well with saving explicit config options, state, context-scope, etc). Now respects both "1" & "0" values for all Config boolean vars and handles them appropriately.

  • Added a lot of before/after table formatting examples to the docstrings, showing the visual impact of the given option.

  • Fixed various format interactions - for example: if you dropped column types you don't want the --- dtype separator to persist, so now automatically dropping that as well (inferring a few other similar cases - leads to more consistent/pleasant formatting when setting a few different options).

  • Renamed set_tbl_hide_column_separator to set_tbl_hide_dtype_separator, as the initial name is misleading (the separator being hidden has nothing to do with columns - it's the one between the name and the dtype). Technically breaking, but I suspect the number of affect people is going to be zero, or very very close to zero, so... ;)

  • Removed set_utf8_tables() as this is never actually used - polars table format defaults to utf8; the only reason to change it to ascii is because you can't output utf8 strings (primitive tty/etc), in which case you are very unlikely to change it back.

    If for some reason you find you do want to do this, can just use set_ascii_tables(False) instead, which will revert formatting back to utf8; no need for a redundant method. The other useful ascii formats (such as markdown) are accessible through a different option anyway - for example: set_tbl_formatting("ASCII_MARKDOWN").

  • Removed set_tbl_change_column_data_type_position_format; the name isn't clear and it's also redundant because you can get the same effect through the better-named set_tbl_hide_dtype_separator.

  • New formatting option set_tbl_column_data_type_inline(True), which inlines the dtype after the name; trades some horizontal space for some vertical space:

    # shape: (3, 2)        shape: (3, 2)
    # ┌─────┬───────┐      ┌───────────┬────────────┐
    # │ abc ┆ xyz   │      │ abc (f64) ┆ xyz (bool) │
    # │ --- ┆ ---   │      ╞═══════════╪════════════╡
    # │ f64 ┆ bool  │      │ 1.0       ┆ true       │
    # ╞═════╪═══════╡      ├╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
    # │ 1.0 ┆ true  │  >>  │ 2.5       ┆ false      │
    # ├╌╌╌╌╌┼╌╌╌╌╌╌╌┤      ├╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
    # │ 2.5 ┆ false │      │ 5.0       ┆ true       │
    # ├╌╌╌╌╌┼╌╌╌╌╌╌╌┤      └───────────┴────────────┘
    # │ 5.0 ┆ true  │
    # └─────┴───────┘
  • Additional test coverage: validates the new formatting options, context-scoping, and the interaction of different formatting options applied at the same time.

Misc:

  • The Config doctest for set_tbl_cols was leaking its environment env change into other tests; once I stopped that, the to_dummies doctest started failing as it was implicitly relying on the higher (non-default) number of columns that got set there; fixed that by slightly modifying the example.

@github-actions github-actions bot added enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars labels Oct 17, 2022
@alexander-beedie
Copy link
Collaborator Author

alexander-beedie commented Oct 17, 2022

The updated docstrings need a bit more work to pass tests :)
Will finish it up tomorrow.

Update: done.

@alexander-beedie alexander-beedie changed the title feat(python, rust): added new Config formatting option set_tbl_column_data_type_inline, fixed reading of env vars, improved interaction of various formatting options feat(python, rust): added new Config formatting option set_tbl_column_data_type_inline, fixed reading of env vars, improved interaction between formatting options Oct 18, 2022
@ritchie46
Copy link
Member

Huge configuration improvement. Thanks!

@ritchie46 ritchie46 merged commit df1a83c into pola-rs:master Oct 18, 2022
@alexander-beedie alexander-beedie deleted the config-fixes-enhancements branch October 20, 2022 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants