8000 [ENH] Add to_markdown method by MarcoGorelli · Pull Request #30350 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

[ENH] Add to_markdown method #30350

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

Merged
merged 24 commits into from
Dec 27, 2019
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
16a3328
:sparkles: Add to_markdown method
Dec 19, 2019
8eb96ec
:pushpin: put tabulate in #optional for io, pin dependency
Dec 20, 2019
00fd8a4
:recycle: remove call to DataFrame.pipe in DataFrame.to_markdown
Dec 20, 2019
65e9f1b
:pushpin: add tabulate to travis-38.yaml
Dec 20, 2019
a273560
:pencil: add DataFrame.to_markdown to API reference file
Dec 20, 2019
14e36e8
:sparkles: add **kwargs to DataFrame.to_markdown
Dec 20, 2019
ee07c68
:white_check_mark: update tests so they work with **kwargs, set skip_…
Dec 20, 2019
d99a54f
:sparkles: add to_markdown to Series
Dec 20, 2019
57dfb7b
:pencil: document to_markdown in Series API reference
Dec 20, 2019
ccb132b
:white_check_mark: update tests so they test Series.to_markdown as well
Dec 20, 2019
bac632e
:arrow_down: Set tabulate dependency at 0.8, before which tests fail
Dec 20, 2019
557e6dd
:pencil: update failing docstring
Dec 20, 2019
01260f2
:pushpin: set tabulate dependency at 0.8.0, not 0.8
Dec 20, 2019
b32d54d
:sparkles: add buf and mode arguments to to_markdown
Dec 20, 2019
68e84d6
:white_check_mark: update tests so they use buf
Dec 20, 2019
882768b
:fire: remove skip_if_no_tabulate, due to module-level fixture
Dec 20, 2019
f46edb1
:pencil: add tabulate to install.rst and _optional, capitalise Markdown
Dec 20, 2019
32d8762
:push_pin: add tabulate unpinned to travis-37.yaml
Dec 20, 2019
c5c3768
:bug: dont all get_filepath_or_buffer with buf equal to sys.stdout
MarcoGorelli Dec 21, 2019
df7880c
:ok_hand: return string if buf is set to None, use shared doc, change…
MarcoGorelli Dec 21, 2019
039e6a9
:pushpin: pin tabulate at 0.8.3
MarcoGorelli Dec 21, 2019
093d63a
:pencil: add kwargs to parameters
Dec 23, 2019
ec77816
:pencil: link to tabulate docs in install.rst
MarcoGorelli Dec 27, 2019
32650f7
:pencil: fix merge conflict in whatsnew
Dec 27, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
✅ update tests so they use buf
  • Loading branch information
Marco Gorelli committed Dec 27, 2019
commit 68e84d6dc56c261d8b17f8b72a3124b36da03311
81 changes: 50 additions & 31 deletions pandas/tests/io/formats/test_to_markdown.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,54 @@
import pandas.util._test_decorators as td
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 |"
)


@td.skip_if_no_tabulate
class TestToMarkdown:
def test_simple(self):
df = pd.DataFrame([1, 2, 3])
result = df.to_markdown()
assert (
result
== "| | 0 |\n|---:|----:|\n| 0 | 1 |\n| 1 | 2 |\n| 2 | 3 |"
)

def test_other_tablefmt(self):
df = pd.DataFrame([1, 2, 3])
result = df.to_markdown(tablefmt="jira")
assert result == "|| || 0 ||\n| 0 | 1 |\n| 1 | 2 |\n| 2 | 3 |"

def test_other_headers(self):
df = pd.DataFrame([1, 2, 3])
result = df.to_markdown(headers=["foo", "bar"])
assert result == (
"| foo | bar |\n|------:|------:|\n| 0 "
"| 1 |\n| 1 | 2 |\n| 2 | 3 |"
)

def test_series(self):
s = pd.Series([1, 2, 3], name="foo")
result = s.to_markdown()
assert result == (
"| | foo |\n|---:|------:|\n| 0 | 1 "
"|\n| 1 | 2 |\n| 2 | 3 |"
)
def test_no_buf(capsys):
df = pd.DataFrame([1, 2, 3])
df.to_markdown()
out, _ = capsys.readouterr()
assert out == "| | 0 |\n|---:|----:|\n| 0 | 1 |\n| 1 | 2 |\n| 2 38CC | 3 |"
0