From ce0497d6753a28cab53f689de672baa0f178357b Mon Sep 17 00:00:00 2001 From: "Praggastis, Brenda" Date: Tue, 23 May 2017 10:13:18 -0700 Subject: [PATCH] tests added for gh-14671, expected behavior of simultaneous use of usecols and names unclear so these tests are commented out --- pandas/tests/io/parser/usecols.py | 32 ++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/pandas/tests/io/parser/usecols.py b/pandas/tests/io/parser/usecols.py index 85fdf802d60b7c..44c3c4dcffccd2 100644 --- a/pandas/tests/io/parser/usecols.py +++ b/pandas/tests/io/parser/usecols.py @@ -478,18 +478,44 @@ def test_uneven_length_cols(self): tm.assert_frame_equal(df, expected) def test_raise_on_usecols_names_mismatch(self): - # see gh-14671 + ## see gh-14671 data = 'a,b,c,d\n1,2,3,4\n5,6,7,8' + msg = 'Usecols do not match names' ## from parsers.py CParserWrapper() + msg2 = 'is not in list' ## from parser.py _handle_usecols() + usecols = ['a','b','c','d'] df = self.read_csv(StringIO(data), usecols=usecols) expected = DataFrame({'a': [1,5], 'b': [2,6], 'c': [3,7], 'd': [4,8]}) tm.assert_frame_equal(df, expected) - msg = 'Usecols do not match names' ## from parsers.py CParserWrapper() - msg2 = 'is not in list' ## from parser.py _handle_usecols() usecols = ['a','b','c','f'] with tm.assert_raises_regex(ValueError, re.compile("'" + msg + '||' + msg2 + "'")): self.read_csv(StringIO(data), usecols=usecols) + usecols = ['a','b','f'] with tm.assert_raises_regex(ValueError, re.compile("'" + msg + '||' + msg2 + "'")): self.read_csv(StringIO(data), usecols=usecols) + + names = ['A', 'B', 'C', 'D'] + + df = self.read_csv(StringIO(data), header=0, names=names) + expected = DataFrame({'A': [1,5], 'B': [2,6], 'C': [3,7], 'D': [4,8]}) + tm.assert_frame_equal(df, expected) + + # usecols = ['A','C'] + # df = self.read_csv(StringIO(data), header=0, names=names, usecols=usecols) + # expected = DataFrame({'A': [1,5], 'C': [3,7]}) + # tm.assert_frame_equal(df, expected) + # + # usecols = [0,2] + # df = self.read_csv(StringIO(data), header=0, names=names, usecols=usecols) + # expected = DataFrame({'A': [1,5], 'C': [3,7]}) + # tm.assert_frame_equal(df, expected) + + + usecols = ['A','B','C','f'] + with tm.assert_raises_regex(ValueError, re.compile("'" + msg + '||' + msg2 + "'")): + self.read_csv(StringIO(data), header=0, names=names, usecols=usecols) + usecols = ['A','B','f'] + with tm.assert_raises_regex(ValueError, re.compile("'" + msg + '||' + msg2 + "'")): + self.read_csv(StringIO(data), names=names, usecols=usecols)