Skip to content

Commit e5e4748

Browse files
committed
BUG: Bug in read_csv where squeeze=True would return a view (GH8217)
1 parent 99bf239 commit e5e4748

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

doc/source/v0.15.0.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,6 @@ Enhancements
480480

481481

482482

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

485484

486485

@@ -538,7 +537,9 @@ There are no experimental changes in 0.15.0
538537
Bug Fixes
539538
~~~~~~~~~
540539

540+
- Bug in ``read_csv`` where ``squeeze=True`` would return a view (:issue:`8217`)
541541
- Bug in checking of table name in ``read_sql`` in certain cases (:issue:`7826`).
542+
- Bug in ``DataFrame.groupby`` where ``Grouper`` does not recognize level when frequency is specified (:issue:`7885`)
542543
- Bug in multiindexes dtypes getting mixed up when DataFrame is saved to SQL table (:issue:`8021`)
543544
- Bug in Series 0-division with a float and integer operand dtypes (:issue:`7785`)
544545
- Bug in ``Series.astype("unicode")`` not calling ``unicode`` on the values correctly (:issue:`7758`)

pandas/io/parsers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ def read(self, nrows=None):
703703
df = DataFrame(col_dict, columns=columns, index=index)
704704

705705
if self.squeeze and len(df.columns) == 1:
706-
return df[df.columns[0]]
706+
return df[df.columns[0]].copy()
707707
return df
708708

709709
def _create_index(self, ret):

pandas/io/tests/test_parsers.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,15 @@ def test_squeeze(self):
263263
tm.assert_isinstance(result, Series)
264264
tm.assert_series_equal(result, expected)
265265

266+
def test_squeeze_no_view(self):
267+
268+
# GH 8217
269+
# series should not be a view
270+
271+
data = """time,data\n0,10\n1,11\n2,12\n4,14\n5,15\n3,13"""
272+
result = self.read_csv(StringIO(data), index_col='time', squeeze=True)
273+
self.assertFalse(result._is_view)
274+
266275
def test_inf_parsing(self):
267276
data = """\
268277
,A

0 commit comments

Comments
 (0)