pandas read_csv: TypeError: 'sage.rings.integer.Integer' object is not iterable

864 views
Skip to first unread message

singlets

unread,
Nov 23, 2013, 8:13:05 PM11/23/13
to sage-...@googlegroups.com
Hello,

This is probably a trivial fix that is available in the sage groups, but I'm striking out searching for preparser / rings.integer / iterable posts. Maybe it is idiosyncratic to pandas?

I'm using pandas for some simple munging; python doesn't like the taste of what sage is passing as the skiprows argument (pd.read_csv() works fine from a terminal ipython session)

sage: import pandas as pd
sage: preparser(False)
sage: pd.read_csv('data/6226BB60.dat', skiprows=86)

Error in lines 2-2 Traceback (most recent call last): File "/mnt/home/HXupCDGU/.sagemathcloud/sage_server.py", line 668, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> File "/usr/local/sage/sage-5.12/local/lib/python2.7/site-packages/pandas/io/parsers.py", line 400, in parser_f return _read(filepath_or_buffer, kwds) File "/usr/local/sage/sage-5.12/local/lib/python2.7/site-packages/pandas/io/parsers.py", line 198, in _read parser = TextFileReader(filepath_or_buffer, **kwds) File "/usr/local/sage/sage-5.12/local/lib/python2.7/site-packages/pandas/io/parsers.py", line 475, in __init__ self.options, self.engine = self._clean_options(options, engine) File "/usr/local/sage/sage-5.12/local/lib/python2.7/site-packages/pandas/io/parsers.py", line 562, in _clean_options skiprows = set() if skiprows is None else set(skiprows) TypeError: 'sage.rings.integer.Integer' object is not iterable

Hints?


Thanks,
Steve
31


William Stein

unread,
Nov 23, 2013, 8:20:28 PM11/23/13
to sage-...@googlegroups.com
On Sat, Nov 23, 2013 at 5:13 PM, singlets <ssin...@coe.edu> wrote:
> Hello,
>
> This is probably a trivial fix that is available in the sage groups, but I'm
> striking out searching for preparser / rings.integer / iterable posts. Maybe
> it is idiosyncratic to pandas?
>
> I'm using pandas for some simple munging; python doesn't like the taste of
> what sage is passing as the skiprows argument. (pd.read_csv() works fine
> from a terminal ipython session)
>
> sage: import pandas as pd
> sage: preparser(False)
> sage: pd.read_csv('data/6226BB60.dat', skiprows=86)

Try int(86) instead of 86?`
> --
> You received this message because you are subscribed to the Google Groups
> "sage-cloud" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sage-cloud+...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sage-cloud/7807af33-d798-4ede-9f75-60c138ff925b%40googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.



--
William Stein
Professor of Mathematics
University of Washington
http://wstein.org

Singleton, Steve

unread,
Nov 23, 2013, 8:35:56 PM11/23/13
to sage-...@googlegroups.com

>
> sage: import pandas as pd
> sage: preparser(False)
> sage: pd.read_csv('data/6226BB60.dat', skiprows=86)

Try int(86) instead of 86?


I'm an idiot...I tried Integer(86)...wrong direction. int() works fine.

Just out of curiosity, why doesn't preparser(False) work here? I'm probably misunderstanding how the preparser works.

Steve

William Stein

unread,
Nov 23, 2013, 8:37:17 PM11/23/13
to sage-...@googlegroups.com
I'm surprised preparser(False) doesn't work. It's hard for me to
test without the data file...

>
> Steve
>
> --
> You received this message because you are subscribed to the Google Groups
> "sage-cloud" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sage-cloud+...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sage-cloud/CANSCVnrC5ri1m6SX667wrwFMnSUpN5pS9nege15cdZtXgUy5zw%40mail.gmail.com.

Singleton, Steve

unread,
Nov 23, 2013, 8:54:21 PM11/23/13
to sage-...@googlegroups.com
Actually, I think this is a glitch with pandas and sage. I get the error any time skiprows!=None in pandas.read_csv() under sage.

Probably not a front-burner issue, but if you think it's worth pursuing you're welcome to take a peek at
/mnt/home/HXupCDGU/fluorescence/*.TXT

Thanks,

Steve


You received this message because you are subscribed to a topic in the Google Groups "sage-cloud" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sage-cloud/Cvl7U0LjI-k/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sage-cloud+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sage-cloud/CACLE5GAbfFax22KbCCvMSUC89Z_8X71Mz3mhMWwdmPec6FUBsA%40mail.gmail.com.

Singleton, Steve

unread,
Nov 23, 2013, 9:00:40 PM11/23/13
to sage-...@googlegroups.com
I think I know the problem...

pandas.io.parsers.read_csv(): skiprows is either a list or an int.  Calling pandas.read.csv(skiprows=[1,2,3] or read.csv(skiprows=int(3) gives no error.  Looks like skiprows is making assumptions about types that are ok in iPython but not sage...

Thanks,
Steve
Reply all
Reply to author
Forward
0 new messages