Skip to content

BUG: Bug in read_csv where squeeze=True would return a view (GH8217) #8218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 8, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion doc/source/v0.15.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,6 @@ Enhancements



- Bug in ``DataFrame.groupby`` where ``Grouper`` does not recognize level when frequency is specified (:issue:`7885`)



Expand Down Expand Up @@ -538,7 +537,9 @@ There are no experimental changes in 0.15.0
Bug Fixes
~~~~~~~~~

- Bug in ``read_csv`` where ``squeeze=True`` would return a view (:issue:`8217`)
- Bug in checking of table name in ``read_sql`` in certain cases (:issue:`7826`).
- Bug in ``DataFrame.groupby`` where ``Grouper`` does not recognize level when frequency is specified (:issue:`7885`)
- Bug in multiindexes dtypes getting mixed up when DataFrame is saved to SQL table (:issue:`8021`)
- Bug in Series 0-division with a float and integer operand dtypes (:issue:`7785`)
- Bug in ``Series.astype("unicode")`` not calling ``unicode`` on the values correctly (:issue:`7758`)
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ def read(self, nrows=None):
df = DataFrame(col_dict, columns=columns, index=index)

if self.squeeze and len(df.columns) == 1:
return df[df.columns[0]]
return df[df.columns[0]].copy()
return df

def _create_index(self, ret):
Expand Down
9 changes: 9 additions & 0 deletions pandas/io/tests/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,15 @@ def test_squeeze(self):
tm.assert_isinstance(result, Series)
tm.assert_series_equal(result, expected)

def test_squeeze_no_view(self):

# GH 8217
# series should not be a view

data = """time,data\n0,10\n1,11\n2,12\n4,14\n5,15\n3,13"""
result = self.read_csv(StringIO(data), index_col='time', squeeze=True)
self.assertFalse(result._is_view)

def test_inf_parsing(self):
data = """\
,A
Expand Down