Skip to content

Commit 2e276fb

Browse files
keshavramaswamyjorisvandenbossche
authored andcommitted
DOC: add sep argument to read_clipboard signature (pandas-dev#14537)
1 parent 7a2bcb6 commit 2e276fb

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

pandas/io/clipboard.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33
from pandas.compat import StringIO
44

55

6-
def read_clipboard(**kwargs): # pragma: no cover
7-
"""
6+
def read_clipboard(sep='\s+', **kwargs): # pragma: no cover
7+
r"""
88
Read text from clipboard and pass to read_table. See read_table for the
99
full argument list
1010
11-
If unspecified, `sep` defaults to '\s+'
11+
Parameters
12+
----------
13+
sep : str, default '\s+'.
14+
A string or regex delimiter. The default of '\s+' denotes
15+
one or more whitespace characters.
1216
1317
Returns
1418
-------
@@ -29,7 +33,7 @@ def read_clipboard(**kwargs): # pragma: no cover
2933
except:
3034
pass
3135

32-
# Excel copies into clipboard with \t seperation
36+
# Excel copies into clipboard with \t separation
3337
# inspect no more then the 10 first lines, if they
3438
# all contain an equal number (>0) of tabs, infer
3539
# that this came from excel and set 'sep' accordingly
@@ -43,12 +47,12 @@ def read_clipboard(**kwargs): # pragma: no cover
4347

4448
counts = set([x.lstrip().count('\t') for x in lines])
4549
if len(lines) > 1 and len(counts) == 1 and counts.pop() != 0:
46-
kwargs['sep'] = '\t'
50+
sep = '\t'
4751

48-
if kwargs.get('sep') is None and kwargs.get('delim_whitespace') is None:
49-
kwargs['sep'] = '\s+'
52+
if sep is None and kwargs.get('delim_whitespace') is None:
53+
sep = '\s+'
5054

51-
return read_table(StringIO(text), **kwargs)
55+
return read_table(StringIO(text), sep=sep, **kwargs)
5256

5357

5458
def to_clipboard(obj, excel=None, sep=None, **kwargs): # pragma: no cover

pandas/io/tests/test_clipboard.py

+2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ def check_round_trip_frame(self, data_type, excel=None, sep=None):
7171
def test_round_trip_frame_sep(self):
7272
for dt in self.data_types:
7373
self.check_round_trip_frame(dt, sep=',')
74+
self.check_round_trip_frame(dt, sep='\s+')
75+
self.check_round_trip_frame(dt, sep='|')
7476

7577
def test_round_trip_frame_string(self):
7678
for dt in self.data_types:

0 commit comments

Comments
 (0)