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

Adding ASCII and Markdown output rendering #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

cproctor
Copy link

Hi! This is my first ever pull request, so please let me know if I've missed some crucial etiquette. I needed regression tables for my Python/markdown-based dissertation build system, and adding it to stargazer seemed like the shortest path. Maybe someone else will benefit too! Here's a rundown of the proposed changes:

I implemented an abstract set of generate_cells methods, following the code paths from the generate_html methods. These return a two-dimensional array of strings, which could be used for other render formats as well. (It might be valuable to refactor the html output to use this where possible.) The 2d grid of cells intentionally limits some of the functionality--no rowspans or colspans are supported.

I also added a few new properties which will be valuable for anyone trying to export markdown regression tables:

  • self.precision_separator = " "
  • self.df_separator = " "
  • self.sig_char = '*'

The separators could be changed to \n, which is particularly nice because tabulate converts newlines into whatever markdown format is requested. The sig_char may need to be replaced by an escaped version of itself in some output contexts.

Once the generate_cells methods were implemented, I use tabulate (new dependency) to render these cells to ascii or any supported flavor of markdown.

I implemented an abstract set of `generate_cells` methods, following the
code paths from the `generate_html` methods. These return a
two-dimensional array of strings, which could be used for other render
formats as well. (It might be valuable to refactor the html output to
use this where possible.) The 2d grid of cells intentionally limits some
of the functionality--no rowspans or colspans are supported.

I also added a few new properties which will be valuable for anyone
trying to export markdown regression tables:

- self.precision_separator = " "
- self.df_separator = " "
- self.sig_char = '*'

The separators could be changed to '\n', which is particularly nice
because tabulate converts newlines into whatever markdown format is
requested. The sig_char may need to be replaced by an escaped version of
itself in some output contexts.

Once the `generate_cells` methods were implemented, I use `tabulate`
(new dependency) to render these cells to ascii or any supported flavor
of markdown.
@toobaz
Copy link
Collaborator

toobaz commented Jun 4, 2020

Hi @cproctor , thank you very much for your contribution.

I'm afraid right now the stargazer code needs deeper changes (#46 ) in order to support further formats in the best way, but once we settle on the general structure it would be great if you could rebase your code: the proposed feature is definitely interesting.

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

Successfully merging this pull request may close these issues.

2 participants