Skip to content

Commit 0665fd4

Browse files
Ajay SaxenaAjay Saxena
Ajay Saxena
authored and
Ajay Saxena
committed
fixed linting and test case as per code review
1 parent d202fd0 commit 0665fd4

File tree

2 files changed

+23
-29
lines changed

2 files changed

+23
-29
lines changed

pandas/io/clipboard.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ def read_clipboard(**kwargs): # pragma: no cover
1414
-------
1515
parsed : DataFrame
1616
"""
17-
encoding = kwargs.pop('encoding','utf-8')
18-
19-
#testing if an invalid encoding is passed to clipboard
20-
if encoding is not None and encoding.lower().replace('-','') != 'utf8':
21-
raise NotImplementedError('reading from clipboard only supports utf-8 encoding')
17+
encoding = kwargs.pop('encoding', 'utf-8')
18+
19+
# only utf-8 is valid for passed value because that's what clipboard
20+
# supports
21+
if encoding is not None and encoding.lower().replace('-', '') != 'utf8':
22+
raise NotImplementedError(
23+
'reading from clipboard only supports utf-8 encoding')
2224

2325
from pandas.util.clipboard import clipboard_get
2426
from pandas.io.parsers import read_table
@@ -80,10 +82,10 @@ def to_clipboard(obj, excel=None, sep=None, **kwargs): # pragma: no cover
8082
- Windows:
8183
- OS X:
8284
"""
83-
encoding = kwargs.pop('encoding','utf-8')
85+
encoding = kwargs.pop('encoding', 'utf-8')
8486

85-
#testing if an invalid encoding is passed to clipboard
86-
if encoding is not None and encoding.lower().replace('-','') != 'utf8':
87+
# testing if an invalid encoding is passed to clipboard
88+
if encoding is not None and encoding.lower().replace('-', '') != 'utf8':
8789
raise ValueError('clipboard only supports utf-8 encoding')
8890

8991
from pandas.util.clipboard import clipboard_set

pandas/io/tests/test_clipboard.py

+13-21
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from pandas import read_clipboard
1010
from pandas import get_option
1111
from pandas.util import testing as tm
12-
from pandas.util.testing import makeCustomDataframe as mkdf, disabled
12+
from pandas.util.testing import makeCustomDataframe as mkdf
1313

1414

1515
try:
@@ -18,7 +18,6 @@
1818
raise nose.SkipTest("no clipboard found")
1919

2020

21-
2221
class TestClipboard(tm.TestCase):
2322

2423
@classmethod
@@ -52,23 +51,24 @@ def setUpClass(cls):
5251
# Test for non-ascii text: GH9263
5352
cls.data['nonascii'] = pd.DataFrame({'en': 'in English'.split(),
5453
'es': 'en español'.split()})
55-
56-
# unicode round trip test for GH 13747
57-
cls.data['utf8'] = pd.DataFrame({'a':['µasd','Ωœ∑´'], 'b':['øπ∆˚¬','œ∑´®']})
54+
# unicode round trip test for GH 13747
55+
cls.data['utf8'] = pd.DataFrame({'a': ['µasd', 'Ωœ∑´'],
56+
'b': ['øπ∆˚¬', 'œ∑´®']})
5857
cls.data_types = list(cls.data.keys())
5958

6059
@classmethod
6160
def tearDownClass(cls):
6261
super(TestClipboard, cls).tearDownClass()
6362
del cls.data_types, cls.data
6463

65-
def check_round_trip_frame(self, data_type, excel=None, sep=None):
64+
def check_round_trip_frame(self, data_type, excel=None, sep=None,
65+
encoding=None):
6666
data = self.data[data_type]
67-
data.to_clipboard(excel=excel, sep=sep)
67+
data.to_clipboard(excel=excel, sep=sep, encoding=encoding)
6868
if sep is not None:
69-
result = read_clipboard(sep=sep, index_col=0)
69+
result = read_clipboard(sep=sep, index_col=0, encoding=encoding)
7070
else:
71-
result = read_clipboard()
71+
result = read_clipboard(encoding=encoding)
7272
tm.assert_frame_equal(data, result, check_dtype=False)
7373

7474
def test_round_trip_frame_sep(self):
@@ -117,23 +117,15 @@ def test_read_clipboard_infer_excel(self):
117117

118118
tm.assert_frame_equal(res, exp)
119119

120-
#test case for testing invalid encoding
120+
# test case for testing invalid encoding
121121
def test_invalid_encoding(self):
122122
data = self.data['string']
123123
with tm.assertRaises(ValueError):
124124
data.to_clipboard(encoding='ascii')
125125
with tm.assertRaises(NotImplementedError):
126-
pd.read_clipboard(encoding='ascii')
126+
pd.read_clipboard(encoding='ascii')
127127

128128
def test_round_trip_valid_encodings(self):
129-
for enc in ['UTF-8','utf-8','utf8']:
129+
for enc in ['UTF-8', 'utf-8', 'utf8']:
130130
for dt in self.data_types:
131-
data = self.data[dt]
132-
data.to_clipboard(encoding=enc)
133-
result = read_clipboard()
134-
tm.assert_frame_equal(data, result, check_dtype=False)
135-
136-
137-
138-
139-
131+
self.check_round_trip_frame(dt, encoding=enc)

0 commit comments

Comments
 (0)