Skip to content

Commit 5bbe99e

Browse files
committed
Merge pull request #8218 from jreback/squeeze
BUG: Bug in read_csv where squeeze=True would return a view (GH8217)
2 parents c207d18 + e5e4748 commit 5bbe99e

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

doc/source/v0.15.0.txt

+2-1
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
- Bug in ``get`` where an ``IndexError`` would not cause the default value to be returned (:issue:`7725`)
@@ -539,7 +538,9 @@ There are no experimental changes in 0.15.0
539538
Bug Fixes
540539
~~~~~~~~~
541540

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

pandas/io/parsers.py

+1-1
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

+9
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)