From c499722613e61ff3d058ca56032023a3d5510518 Mon Sep 17 00:00:00 2001 From: Keshav Ramaswamy Date: Thu, 3 Nov 2016 20:37:11 -0400 Subject: [PATCH 1/2] added argument sep='\s+' to read_clipboard signature along with tests --- pandas/io/clipboard.py | 17 ++++++++++------- pandas/io/tests/test_clipboard.py | 2 ++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/pandas/io/clipboard.py b/pandas/io/clipboard.py index 2109e1c5d6d4c..89de7cf0edff3 100644 --- a/pandas/io/clipboard.py +++ b/pandas/io/clipboard.py @@ -3,12 +3,15 @@ from pandas.compat import StringIO -def read_clipboard(**kwargs): # pragma: no cover +def read_clipboard(sep='\s+', **kwargs): # pragma: no cover """ 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+', one whitespace or more + A string or regex delimiter. Returns ------- @@ -29,7 +32,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 +46,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: From e8edce9b2adee98f84940839f6cf9d09784001e0 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Mon, 7 Nov 2016 21:50:01 +0100 Subject: [PATCH 2/2] make raw string for doc building --- pandas/io/clipboard.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pandas/io/clipboard.py b/pandas/io/clipboard.py index 89de7cf0edff3..6f6f1366a6732 100644 --- a/pandas/io/clipboard.py +++ b/pandas/io/clipboard.py @@ -4,14 +4,15 @@ 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 Parameters ---------- - sep : str, default '\s+', one whitespace or more - A string or regex delimiter. + sep : str, default '\s+'. + A string or regex delimiter. The default of '\s+' denotes + one or more whitespace characters. Returns -------