Skip to content

Commit 47eb219

Browse files
authored
Add tests for usecols and index col combinations (#44951)
1 parent 50adb83 commit 47eb219

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

pandas/tests/io/parser/usecols/test_usecols_basic.py

+22
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,28 @@ def test_usecols_implicit_index_col(all_parsers):
174174
tm.assert_frame_equal(result, expected)
175175

176176

177+
def test_usecols_index_col_middle(all_parsers):
178+
# GH#9098
179+
parser = all_parsers
180+
data = """a,b,c,d
181+
1,2,3,4
182+
"""
183+
result = parser.read_csv(StringIO(data), usecols=["b", "c", "d"], index_col="c")
184+
expected = DataFrame({"b": [2], "d": [4]}, index=Index([3], name="c"))
185+
tm.assert_frame_equal(result, expected)
186+
187+
188+
def test_usecols_index_col_end(all_parsers):
189+
# GH#9098
190+
parser = all_parsers
191+
data = """a,b,c,d
192+
1,2,3,4
193+
"""
194+
result = parser.read_csv(StringIO(data), usecols=["b", "c", "d"], index_col="d")
195+
expected = DataFrame({"b": [2], "c": [3]}, index=Index([4], name="d"))
196+
tm.assert_frame_equal(result, expected)
197+
198+
177199
def test_usecols_regex_sep(all_parsers):
178200
# see gh-2733
179201
parser = all_parsers

0 commit comments

Comments
 (0)