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

ENH: RST support #60616

Open
1 of 3 tasks
R5dan opened this issue Dec 29, 2024 · 3 comments
Open
1 of 3 tasks

ENH: RST support #60616

R5dan opened this issue Dec 29, 2024 · 3 comments
Labels
Enhancement Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@R5dan
Copy link

R5dan commented Dec 29, 2024

Feature Type

  • Adding new functionality to pandas

  • Changing existing functionality in pandas

  • Removing existing functionality in pandas

Problem Description

I wish I could use ReStructured Text with pandas

Feature Description

The end users code:

import pandas as pd
df=pd.read_rst(rst)
df.to_rst()

I believe tabulate has a way to do this.

Alternative Solutions

I also built a way to make rst tables.

Additional Context

I think Grid Tables would be best for pandas (or Simple Tables)

I did not use sudo-code in the examples due to complexity and that examples of how to do this can be seen in the above packages. See RST docs for what they look like.

@R5dan R5dan added Enhancement Needs Triage Issue that has not been reviewed by a pandas team member labels Dec 29, 2024
@haiyashah
Copy link

haiyashah commented Jan 1, 2025

Assign

@haiyashah
Copy link

haiyashah commented Jan 1, 2025

import pandas as pd
from tabulate import tabulate
from docutils.parsers.rst import tableparser
from docutils.statemachine import StringList

def read_rst(rst_string):
parser = tableparser.GridTableParser()
table_data = parser.parse(StringList(rst_string.splitlines()))
header = ["".join(cell) for cell in table_data[0]]
rows = [[cell[0] for cell in row] for row in table_data[1]]
return pd.DataFrame(rows, columns=header)

def to_rst(df):
return tabulate(df, headers="keys", tablefmt="grid")

rst_table = """
+-----+-------+
| ID | Name |
+=====+=======+
| 1 | Alice |
+-----+-------+
| 2 | Bob |
+-----+-------+
"""

df = read_rst(rst_table)
print(df)

rst_output = to_rst(df)
print(rst_output)

@R5dan
Copy link
Author

R5dan commented Jan 1, 2025

I'm not saying its not possible to transform them, but its not as simple as it could be. It should be able to be done inside pandas

rst_table = """ +-----+-------+ | ID | Name | +=====+=======+ | 1 | Alice | +-----+-------+ | 2 | Bob | +-----+-------+ """

Thats an invalid RST table, so shouldn't be parsable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

No branches or pull requests

2 participants