-
-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ENH] Add to_markdown method (#30350)
- Loading branch information
1 parent
fb20b26
commit 7ab73a9
Showing
13 changed files
with
147 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ dependencies: | |
- pyarrow | ||
- pytz | ||
- s3fs | ||
- tabulate | ||
- pyreadstat | ||
- pip | ||
- pip: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,4 @@ dependencies: | |
- nomkl | ||
- pytz | ||
- pip | ||
- tabulate==0.8.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -578,3 +578,4 @@ Serialization / IO / conversion | |
Series.to_string | ||
Series.to_clipboard | ||
Series.to_latex | ||
Series.to_markdown |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from io import StringIO | ||
|
||
import pytest | ||
|
||
import pandas as pd | ||
|
||
pytest.importorskip("tabulate") | ||
|
||
|
||
def test_simple(): | ||
buf = StringIO() | ||
df = pd.DataFrame([1, 2, 3]) | ||
df.to_markdown(buf=buf) | ||
result = buf.getvalue() | ||
assert ( | ||
result == "| | 0 |\n|---:|----:|\n| 0 | 1 |\n| 1 | 2 |\n| 2 | 3 |" | ||
) | ||
|
||
|
||
def test_other_tablefmt(): | ||
buf = StringIO() | ||
df = pd.DataFrame([1, 2, 3]) | ||
df.to_markdown(buf=buf, tablefmt="jira") | ||
result = buf.getvalue() | ||
assert result == "|| || 0 ||\n| 0 | 1 |\n| 1 | 2 |\n| 2 | 3 |" | ||
|
||
|
||
def test_other_headers(): | ||
buf = StringIO() | ||
df = pd.DataFrame([1, 2, 3]) | ||
df.to_markdown(buf=buf, headers=["foo", "bar"]) | ||
result = buf.getvalue() | ||
assert result == ( | ||
"| foo | bar |\n|------:|------:|\n| 0 " | ||
"| 1 |\n| 1 | 2 |\n| 2 | 3 |" | ||
) | ||
|
||
|
||
def test_series(): | ||
buf = StringIO() | ||
s = pd.Series([1, 2, 3], name="foo") | ||
s.to_markdown(buf=buf) | ||
result = buf.getvalue() | ||
assert result == ( | ||
"| | foo |\n|---:|------:|\n| 0 | 1 " | ||
"|\n| 1 | 2 |\n| 2 | 3 |" | ||
) | ||
|
||
|
||
def test_no_buf(capsys): | ||
df = pd.DataFrame([1, 2, 3]) | ||
result = df.to_markdown() | ||
assert ( | ||
result == "| | 0 |\n|---:|----:|\n| 0 | 1 |\n| 1 | 2 |\n| 2 | 3 |" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters