Repository: pandas-dev/pandas

Issue:
View returned when using squeeze=True with read_csv?
``` python
In [1]: import pandas as pd, StringIO

In [2]: csv = StringIO.StringIO('time,data\n0,10\n1,11\n2,12\n4,14\n5,15\n3,13')

In [3]: df = pd.read_csv(csv, index_col='time')

In [4]: df
Out[4]: 
      data
time      
0       10
1       11
2       12
4       14
5       15
3       13

In [5]: df.sort(inplace=True)

In [6]: df
Out[6]: 
      data
time      
0       10
1       11
2       12
3       13
4       14
5       15
```

Specifying `squeeze=True` returns a view instead of first-class object? Is this by design and if so, why?

As of 0.14.1, `inplace=True` is the default (related #5190) for series sorts so the following error will occur by default if `squeeze=True` was specified.

``` python
In [1]: import pandas as pd, StringIO

In [2]: csv = StringIO.StringIO('time,data\n0,10\n1,11\n2,12\n4,14\n5,15\n3,13')

In [3]: df = pd.read_csv(csv, index_col='time', squeeze=True)

In [4]: df
Out[4]: 
      data
time      
0       10
1       11
2       12
4       14
5       15
3       13

In [5]: df.sort(inplace=True)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-5-850f333de498> in <module>()
----> 1 df.sort(inplace=True)

C:\WinPython-64bit-2.7.5.3\python-2.7.5.amd64\lib\site-packages\pandas\core\series.pyc in sort(self, axis, ascending, kind, na_position, inplace)
   1651                           kind=kind,
   1652                           na_position=na_position,
-> 1653                           inplace=inplace)
   1654 
   1655     def order(self, na_last=None, ascending=True, kind='quicksort', na_position='last', inplace=False):

C:\WinPython-64bit-2.7.5.3\python-2.7.5.amd64\lib\site-packages\pandas\core\series.pyc in order(self, na_last, ascending, kind, na_position, inplace)
   1684         # GH 5856/5853
   1685         if inplace and self._is_cached:
-> 1686             raise ValueError("This Series is a view of some other array, to "
   1687                              "sort in-place you must create a copy")
   1688 

ValueError: This Series is a view of some other array, to sort in-place you must create a copy
```



Discussion:

Resolving patch:
diff --git a/pandas/io/parsers.py b/pandas/io/parsers.py
--- a/pandas/io/parsers.py
+++ b/pandas/io/parsers.py
@@ -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):


Test patch:
diff --git a/pandas/io/tests/test_parsers.py b/pandas/io/tests/test_parsers.py
--- a/pandas/io/tests/test_parsers.py
+++ b/pandas/io/tests/test_parsers.py
@@ -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