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] Add to_markdown method #30350

Merged
merged 24 commits into from
Dec 27, 2019
Merged

Conversation

MarcoGorelli
Copy link
Member

@pep8speaks
Copy link

pep8speaks commented Dec 19, 2019

Hello @MarcoGorelli! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2019-12-27 16:16:15 UTC

@MarcoGorelli MarcoGorelli force-pushed the add-to-markdown branch 4 times, most recently from 1a1ddee to 8282511 Compare December 19, 2019 18:13
environment.yml Outdated Show resolved Hide resolved
pandas/core/frame.py Outdated Show resolved Hide resolved
@jbrockmendel
Copy link
Member

should Series support this too? does tabulate have something that could be used for a read_markdown to round-trip?

Copy link
Contributor

@TomAugspurger TomAugspurger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need to add tabulate to at least one of the ci/deps/ files

pandas/core/frame.py Outdated Show resolved Hide resolved
pandas/core/frame.py Outdated Show resolved Hide resolved
doc/source/whatsnew/v1.0.0.rst Outdated Show resolved Hide resolved
@TomAugspurger TomAugspurger added the IO Data IO issues that don't fit into a more specific label label Dec 19, 2019
@MarcoGorelli MarcoGorelli changed the title ✨ Add to_markdown method [ENH] Add to_markdown method Dec 20, 2019
pandas/core/series.py Outdated Show resolved Hide resolved
@MarcoGorelli MarcoGorelli changed the title [ENH] Add to_markdown method [wip] [ENH] Add to_markdown method Dec 20, 2019
ci/deps/travis-38.yaml Outdated Show resolved Hide resolved
@MarcoGorelli
Copy link
Member Author

MarcoGorelli commented Dec 20, 2019

should Series support this too? does tabulate have something that could be used for a read_markdown to round-trip?

Sure, I've added it to Series.

I haven't found anything in the tabulate source code that can be easily used for read_markdown, but it would be a nice enhancement to work on.

Thank you @TomAugspurger and @jbrockmendel for your reviews!

@darkdragon-001
Copy link

I haven't found anything in the tabulate source code that can be easily used for read_markdown, but it would be a nice enhancement to work on.

Maybe CSV code with | separator could work. One just has to ignore the header separation line. Maybe empty columns will be added because of the outer border separators and should be removed in post-processing automatically.

@MarcoGorelli MarcoGorelli changed the title [wip] [ENH] Add to_markdown method [ENH] Add to_markdown method Dec 20, 2019
pandas/core/frame.py Outdated Show resolved Hide resolved
pandas/core/frame.py Outdated Show resolved Hide resolved
pandas/tests/io/formats/test_to_markdown.py Outdated Show resolved Hide resolved
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add to install.rst and pandas/compat/_optional.py

ci/deps/travis-38.yaml Outdated Show resolved Hide resolved
pandas/core/frame.py Outdated Show resolved Hide resolved
Print a DataFrame in markdown-friendly format.

.. versionadded:: 1.0

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a Parameters section here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, done. Wasn't sure what to write for mode, as the docstring for pandas/io/common.py::get_filepath_or_buffer just says

mode : str, optional

and, as far as I can tell, the parameter is only used in the following conditions:

if is_s3_url(filepath_or_buffer):
if is_gcs_url(filepath_or_buffer):

pandas/core/frame.py Outdated Show resolved Hide resolved
pandas/core/series.py Show resolved Hide resolved
pandas/tests/io/formats/test_to_markdown.py Outdated Show resolved Hide resolved
@MarcoGorelli MarcoGorelli changed the title [ENH] Add to_markdown method wip [ENH] Add to_markdown method Dec 20, 2019
@MarcoGorelli MarcoGorelli force-pushed the add-to-markdown branch 6 times, most recently from 48289b5 to a572e29 Compare December 21, 2019 17:54
@MarcoGorelli
Copy link
Member Author

@jreback I've mentioned tabulate and added a link to its docs in install.rst, then rebased

@datapythonista Thanks! I've read through the thread you linked to. There seems to still be some disagreement among the core team about the issue though, so I'm not sure what to do and am in no position to pick sides

@jreback
Copy link
Contributor

jreback commented Dec 27, 2019

Thanks @MarcoGorelli, this is quite useful.

But personally I think this is a great opportunity to implement this as a third party module, and start to work on making it easier to extend pandas with I/O adapters like this (see #26804)

@datapythonista that's orthogonal, and to be honest this IS almost entirely a third-party module.

It is much much easier to simply refactor later than to re-factor while adding something new.

@jreback jreback merged commit 7ab73a9 into pandas-dev:master Dec 27, 2019
@jreback
Copy link
Contributor

jreback commented Dec 27, 2019

thanks @MarcoGorelli very nice!

AlexKirko pushed a commit to AlexKirko/pandas that referenced this pull request Dec 29, 2019
keechongtan added a commit to keechongtan/pandas that referenced this pull request Dec 29, 2019
…ndexing-1row-df

* upstream/master: (333 commits)
  CI: troubleshoot Web_and_Docs failing (pandas-dev#30534)
  WARN: Ignore NumbaPerformanceWarning in test suite (pandas-dev#30525)
  DEPR: camelCase in offsets, get_offset (pandas-dev#30340)
  PERF: implement scalar ops blockwise (pandas-dev#29853)
  DEPR: Remove Series.compress (pandas-dev#30514)
  ENH: Add numba engine for rolling apply (pandas-dev#30151)
  [ENH] Add to_markdown method (pandas-dev#30350)
  DEPR: Deprecate pandas.np module (pandas-dev#30386)
  ENH: Add ignore_index for df.drop_duplicates (pandas-dev#30405)
  BUG: The setting xrot=0 in DataFrame.hist() doesn't work with by and subplots pandas-dev#30288 (pandas-dev#30491)
  CI: Fix GBQ Tests (pandas-dev#30478)
  Bug groupby quantile listlike q and int columns (pandas-dev#30485)
  ENH: Add ignore_index for df.sort_values and series.sort_values (pandas-dev#30402)
  TYP: Typing hints in pandas/io/formats/{css,csvs}.py (pandas-dev#30398)
  BUG: raise on non-hashable Index name, closes pandas-dev#29069 (pandas-dev#30335)
  Replace "foo!r" to "repr(foo)" syntax pandas-dev#29886 (pandas-dev#30502)
  BUG: preserve EA dtype in transpose (pandas-dev#30091)
  BLD: add check to prevent tempita name error, clsoes pandas-dev#28836 (pandas-dev#30498)
  REF/TST: method-specific files for test_append (pandas-dev#30503)
  marked unused parameters (pandas-dev#30504)
  ...
@MarcoGorelli MarcoGorelli deleted the add-to-markdown branch January 24, 2020 13:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IO Data IO issues that don't fit into a more specific label
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DataFrame could have a to_markdown method.
7 participants