diff --git a/pandas/io/clipboard.py b/pandas/io/clipboard.py index 2109e1c5d6d4c..6f6f1366a6732 100644 --- a/pandas/io/clipboard.py +++ b/pandas/io/clipboard.py @@ -3,12 +3,16 @@ from pandas.compat import StringIO -def read_clipboard(**kwargs): # pragma: no cover - """ +def read_clipboard(sep='\s+', **kwargs): # pragma: no cover + r""" Read text from clipboard and pass to read_table. See read_table for the full argument list - If unspecified, `sep` defaults to '\s+' + Parameters + ---------- + sep : str, default '\s+'. + A string or regex delimiter. The default of '\s+' denotes + one or more whitespace characters. Returns ------- @@ -29,7 +33,7 @@ def read_clipboard(**kwargs): # pragma: no cover except: pass - # Excel copies into clipboard with \t seperation + # Excel copies into clipboard with \t separation # inspect no more then the 10 first lines, if they # all contain an equal number (>0) of tabs, infer # that this came from excel and set 'sep' accordingly @@ -43,12 +47,12 @@ def read_clipboard(**kwargs): # pragma: no cover counts = set([x.lstrip().count('\t') for x in lines]) if len(lines) > 1 and len(counts) == 1 and counts.pop() != 0: - kwargs['sep'] = '\t' + sep = '\t' - if kwargs.get('sep') is None and kwargs.get('delim_whitespace') is None: - kwargs['sep'] = '\s+' + if sep is None and kwargs.get('delim_whitespace') is None: + sep = '\s+' - return read_table(StringIO(text), **kwargs) + return read_table(StringIO(text), sep=sep, **kwargs) def to_clipboard(obj, excel=None, sep=None, **kwargs): # pragma: no cover diff --git a/pandas/io/tests/test_clipboard.py b/pandas/io/tests/test_clipboard.py index a7da27a2f75dd..6c5ee6fcd22ba 100644 --- a/pandas/io/tests/test_clipboard.py +++ b/pandas/io/tests/test_clipboard.py @@ -71,6 +71,8 @@ def check_round_trip_frame(self, data_type, excel=None, sep=None): def test_round_trip_frame_sep(self): for dt in self.data_types: self.check_round_trip_frame(dt, sep=',') + self.check_round_trip_frame(dt, sep='\s+') + self.check_round_trip_frame(dt, sep='|') def test_round_trip_frame_string(self): for dt in self.data_types: