Skip to content

Commit 9ed14cf

Browse files
committed
CLN: conform read_clipboard / to_clipboard to new io standards
removed to io.clipboard (from io.parsers)
1 parent 4f482d5 commit 9ed14cf

File tree

5 files changed

+49
-35
lines changed

5 files changed

+49
-35
lines changed

RELEASE.rst

+1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ pandas 0.11.1
127127
- added ``pandas.io.api`` for i/o imports
128128
- removed ``Excel`` support to ``pandas.io.excel``
129129
- added top-level ``pd.read_sql`` and ``to_sql`` DataFrame methods
130+
- removed ``clipboard`` support to ``pandas.io.clipboard``
130131
- the ``method`` and ``axis`` arguments of ``DataFrame.replace()`` are
131132
deprecated
132133
- Implement ``__nonzero__`` for ``NDFrame`` objects (GH3691_, GH3696_)

pandas/core/generic.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -492,8 +492,8 @@ def to_hdf(self, path_or_buf, key, **kwargs):
492492
return pytables.to_hdf(path_or_buf, key, self, **kwargs)
493493

494494
def to_clipboard(self):
495-
from pandas.io import parsers
496-
parsers.to_clipboard(self)
495+
from pandas.io import clipboard
496+
clipboard.to_clipboard(self)
497497

498498
# install the indexerse
499499
for _name, _indexer in indexing.get_indexers_list():

pandas/io/api.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
Data IO api
33
"""
44

5-
from pandas.io.parsers import (read_csv, read_table, read_clipboard,
6-
read_fwf, to_clipboard)
5+
from pandas.io.parsers import read_csv, read_table, read_fwf
6+
from pandas.io.clipboard import read_clipboard
77
from pandas.io.excel import ExcelFile, ExcelWriter, read_excel
88
from pandas.io.pytables import HDFStore, Term, get_store, read_hdf
99
from pandas.io.html import read_html

pandas/io/clipboard.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
""" io on the clipboard """
2+
3+
def read_clipboard(**kwargs): # pragma: no cover
4+
"""
5+
Read text from clipboard and pass to read_table. See read_table for the
6+
full argument list
7+
8+
Returns
9+
-------
10+
parsed : DataFrame
11+
"""
12+
from pandas.util.clipboard import clipboard_get
13+
text = clipboard_get()
14+
return read_table(StringIO(text), **kwargs)
15+
16+
17+
def to_clipboard(obj): # pragma: no cover
18+
"""
19+
Attempt to write text representation of object to the system clipboard
20+
21+
Notes
22+
-----
23+
Requirements for your platform
24+
- Linux: xsel command line tool
25+
- Windows: Python win32 extensions
26+
- OS X:
27+
"""
28+
from pandas.util.clipboard import clipboard_set
29+
clipboard_set(str(obj))
30+
31+

pandas/io/parsers.py

+13-31
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import re
66
from itertools import izip
77
import csv
8+
from warnings import warn
89

910
import numpy as np
1011

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

429430

430-
def read_clipboard(**kwargs): # pragma: no cover
431-
"""
432-
Read text from clipboard and pass to read_table. See read_table for the
433-
full argument list
434-
435-
Returns
436-
-------
437-
parsed : DataFrame
438-
"""
439-
from pandas.util.clipboard import clipboard_get
440-
text = clipboard_get()
441-
return read_table(StringIO(text), **kwargs)
442-
443-
444-
def to_clipboard(obj): # pragma: no cover
445-
"""
446-
Attempt to write text representation of object to the system clipboard
447-
448-
Notes
449-
-----
450-
Requirements for your platform
451-
- Linux: xsel command line tool
452-
- Windows: Python win32 extensions
453-
- OS X:
454-
"""
455-
from pandas.util.clipboard import clipboard_set
456-
clipboard_set(str(obj))
457-
458-
459431
# common NA values
460432
# no longer excluding inf representations
461433
# '1.#INF','-1.#INF', '1.#INF000000',
@@ -1940,15 +1912,25 @@ def _make_reader(self, f):
19401912
self.data = FixedWidthReader(f, self.colspecs, self.delimiter)
19411913

19421914

1915+
##### deprecations in 0.11.1 #####
1916+
##### remove in 0.12 #####
1917+
1918+
from pandas.io import clipboard
1919+
def read_clipboard(**kwargs):
1920+
warn("read_clipboard is now a top-level accessible via pandas.read_clipboard", FutureWarning)
1921+
clipboard.read_clipboard(**kwargs)
1922+
1923+
def to_clipboard(obj):
1924+
warn("to_clipboard is now an object level method accessible via obj.to_clipboard()", FutureWarning)
1925+
clipboard.to_clipboard(obj)
1926+
19431927
from pandas.io import excel
19441928
class ExcelWriter(excel.ExcelWriter):
19451929
def __init__(self, path):
1946-
from warnings import warn
19471930
warn("ExcelWriter can now be imported from: pandas.io.excel", FutureWarning)
19481931
super(ExcelWriter, self).__init__(path)
19491932

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

0 commit comments

Comments
 (0)