Skip to content

CLN: conform read_clipboard / to_clipboard to new io standards #3824

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 1 commit into from
Jun 9, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ pandas 0.11.1
- added ``pandas.io.api`` for i/o imports
- removed ``Excel`` support to ``pandas.io.excel``
- added top-level ``pd.read_sql`` and ``to_sql`` DataFrame methods
- removed ``clipboard`` support to ``pandas.io.clipboard``
- the ``method`` and ``axis`` arguments of ``DataFrame.replace()`` are
deprecated
- Implement ``__nonzero__`` for ``NDFrame`` objects (GH3691_, GH3696_)
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,8 @@ def to_hdf(self, path_or_buf, key, **kwargs):
return pytables.to_hdf(path_or_buf, key, self, **kwargs)

def to_clipboard(self):
from pandas.io import parsers
parsers.to_clipboard(self)
from pandas.io import clipboard
clipboard.to_clipboard(self)

# install the indexerse
for _name, _indexer in indexing.get_indexers_list():
Expand Down
4 changes: 2 additions & 2 deletions pandas/io/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Data IO api
"""

from pandas.io.parsers import (read_csv, read_table, read_clipboard,
read_fwf, to_clipboard)
from pandas.io.parsers import read_csv, read_table, read_fwf
from pandas.io.clipboard import read_clipboard
from pandas.io.excel import ExcelFile, ExcelWriter, read_excel
from pandas.io.pytables import HDFStore, Term, get_store, read_hdf
from pandas.io.html import read_html
Expand Down
31 changes: 31 additions & 0 deletions pandas/io/clipboard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
""" io on the clipboard """

def read_clipboard(**kwargs): # pragma: no cover
"""
Read text from clipboard and pass to read_table. See read_table for the
full argument list

Returns
-------
parsed : DataFrame
"""
from pandas.util.clipboard import clipboard_get
text = clipboard_get()
return read_table(StringIO(text), **kwargs)


def to_clipboard(obj): # pragma: no cover
"""
Attempt to write text representation of object to the system clipboard

Notes
-----
Requirements for your platform
- Linux: xsel command line tool
Copy link
Member

Choose a reason for hiding this comment

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

is this correct? i used to only have xclip and it worked fine (xclip sucks with tmux so i now use xsel)...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just moved this from io.parsers
actually no tests for it

Copy link
Member

Choose a reason for hiding this comment

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

ok i will write one and submit a pr...

- Windows: Python win32 extensions
- OS X:
"""
from pandas.util.clipboard import clipboard_set
clipboard_set(str(obj))


44 changes: 13 additions & 31 deletions pandas/io/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import re
from itertools import izip
import csv
from warnings import warn

import numpy as np

Expand Down Expand Up @@ -427,35 +428,6 @@ def read_fwf(filepath_or_buffer, colspecs=None, widths=None, **kwds):
return _read(filepath_or_buffer, kwds)


def read_clipboard(**kwargs): # pragma: no cover
"""
Read text from clipboard and pass to read_table. See read_table for the
full argument list

Returns
-------
parsed : DataFrame
"""
from pandas.util.clipboard import clipboard_get
text = clipboard_get()
return read_table(StringIO(text), **kwargs)


def to_clipboard(obj): # pragma: no cover
"""
Attempt to write text representation of object to the system clipboard

Notes
-----
Requirements for your platform
- Linux: xsel command line tool
- Windows: Python win32 extensions
- OS X:
"""
from pandas.util.clipboard import clipboard_set
clipboard_set(str(obj))


# common NA values
# no longer excluding inf representations
# '1.#INF','-1.#INF', '1.#INF000000',
Expand Down Expand Up @@ -1940,15 +1912,25 @@ def _make_reader(self, f):
self.data = FixedWidthReader(f, self.colspecs, self.delimiter)


##### deprecations in 0.11.1 #####
##### remove in 0.12 #####

from pandas.io import clipboard
def read_clipboard(**kwargs):
warn("read_clipboard is now a top-level accessible via pandas.read_clipboard", FutureWarning)
clipboard.read_clipboard(**kwargs)

def to_clipboard(obj):
warn("to_clipboard is now an object level method accessible via obj.to_clipboard()", FutureWarning)
clipboard.to_clipboard(obj)

from pandas.io import excel
class ExcelWriter(excel.ExcelWriter):
def __init__(self, path):
from warnings import warn
warn("ExcelWriter can now be imported from: pandas.io.excel", FutureWarning)
super(ExcelWriter, self).__init__(path)

class ExcelFile(excel.ExcelFile):
def __init__(self, path_or_buf, kind=None, **kwds):
from warnings import warn
warn("ExcelFile can now be imported from: pandas.io.excel", FutureWarning)
super(ExcelFile, self).__init__(path_or_buf, kind=kind, **kwds)