From 9ed14cf62c6f8b592e5776d4c62bab53e3356ac8 Mon Sep 17 00:00:00 2001 From: jreback Date: Sun, 9 Jun 2013 19:12:43 -0400 Subject: [PATCH] CLN: conform read_clipboard / to_clipboard to new io standards removed to io.clipboard (from io.parsers) --- RELEASE.rst | 1 + pandas/core/generic.py | 4 ++-- pandas/io/api.py | 4 ++-- pandas/io/clipboard.py | 31 +++++++++++++++++++++++++++++ pandas/io/parsers.py | 44 +++++++++++++----------------------------- 5 files changed, 49 insertions(+), 35 deletions(-) create mode 100644 pandas/io/clipboard.py diff --git a/RELEASE.rst b/RELEASE.rst index 4d85834706e80..eca69d824d377 100644 --- a/RELEASE.rst +++ b/RELEASE.rst @@ -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_) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 7dd0315d7d90e..5533584745167 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -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(): diff --git a/pandas/io/api.py b/pandas/io/api.py index e4c0c8c0c77f0..f17351921f83f 100644 --- a/pandas/io/api.py +++ b/pandas/io/api.py @@ -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 diff --git a/pandas/io/clipboard.py b/pandas/io/clipboard.py new file mode 100644 index 0000000000000..4aa8db414386b --- /dev/null +++ b/pandas/io/clipboard.py @@ -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 + - Windows: Python win32 extensions + - OS X: + """ + from pandas.util.clipboard import clipboard_set + clipboard_set(str(obj)) + + diff --git a/pandas/io/parsers.py b/pandas/io/parsers.py index 54ba7536afaee..6e937ba696e39 100644 --- a/pandas/io/parsers.py +++ b/pandas/io/parsers.py @@ -5,6 +5,7 @@ import re from itertools import izip import csv +from warnings import warn import numpy as np @@ -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', @@ -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)