Skip to content

Commit c2da129

Browse files
committed
BUG: close #835, add option to suppress index inference
1 parent 95cfc7c commit c2da129

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

RELEASE.rst

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ pandas 0.7.1
5151
- Fix to_records where columns are non-strings (#822)
5252
- Fix Index.intersection where indices have incomparable types (#811)
5353
- Fix ExcelFile throwing an exception for two-line file (#837)
54+
- Add ability to suppress index inference in csv parser (related to #835)
5455

5556
pandas 0.7.0
5657
============

pandas/io/parsers.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def read_csv(filepath_or_buffer, sep=',', header=0, index_col=None, names=None,
9191
skiprows=None, na_values=None, parse_dates=False,
9292
date_parser=None, nrows=None, iterator=False, chunksize=None,
9393
skip_footer=0, converters=None, verbose=False, delimiter=None,
94-
encoding=None):
94+
encoding=None, infer_index=True):
9595
if hasattr(filepath_or_buffer, 'read'):
9696
f = filepath_or_buffer
9797
else:
@@ -117,7 +117,8 @@ def read_csv(filepath_or_buffer, sep=',', header=0, index_col=None, names=None,
117117
skip_footer=skip_footer,
118118
converters=converters,
119119
verbose=verbose,
120-
encoding=encoding)
120+
encoding=encoding,
121+
infer_index=infer_index)
121122

122123
if nrows is not None:
123124
return parser.get_chunk(nrows)
@@ -204,6 +205,8 @@ class TextParser(object):
204205
Number of line at bottom of file to skip
205206
encoding : string, default None
206207
Encoding to use for UTF when reading/writing (ex. 'utf-8')
208+
infer_index : boolean, default True
209+
If index_col is None, will try to infer index unless this is False
207210
"""
208211

209212
# common NA values
@@ -217,7 +220,7 @@ def __init__(self, f, delimiter=None, names=None, header=0,
217220
index_col=None, na_values=None, parse_dates=False,
218221
date_parser=None, chunksize=None, skiprows=None,
219222
skip_footer=0, converters=None, verbose=False,
220-
encoding=None):
223+
encoding=None, infer_index=True):
221224
"""
222225
Workhorse function for processing nested list into DataFrame
223226
@@ -234,7 +237,7 @@ def __init__(self, f, delimiter=None, names=None, header=0,
234237
self.chunksize = chunksize
235238
self.passed_names = names is not None
236239
self.encoding = encoding
237-
240+
self.infer_index = infer_index
238241

239242
if com.is_integer(skiprows):
240243
skiprows = range(skiprows)
@@ -401,7 +404,7 @@ def _get_index_name(self):
401404
return line
402405

403406
if implicit_first_cols > 0:
404-
if self.index_col is None:
407+
if self.index_col is None and self.infer_index:
405408
if implicit_first_cols == 1:
406409
self.index_col = 0
407410
else:

0 commit comments

Comments
 (0)