Skip to content

View returned when using squeeze=True with read_csv? #8217

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

Closed
patricktokeeffe opened this issue Sep 8, 2014 · 1 comment · Fixed by #8218
Closed

View returned when using squeeze=True with read_csv? #8217

patricktokeeffe opened this issue Sep 8, 2014 · 1 comment · Fixed by #8218
Labels
Bug IO CSV read_csv, to_csv
Milestone

Comments

@patricktokeeffe
Copy link
Contributor

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.

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
@jreback
Copy link
Contributor

jreback commented Sep 8, 2014

easy enough

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug IO CSV read_csv, to_csv
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants