Skip to content
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

Exception calling to_string on empty Series #488

Closed
craustin opened this issue Dec 14, 2011 · 3 comments

Comments

@craustin
Copy link

commented Dec 14, 2011

from pandas import Series
s = Series({})
s.to_string()

pandas\core\series.pyc in to_string(self, buf,
na_rep, float_format, nanRep)
460 na_rep = nanRep
461
--> 462 the_repr = self._get_repr(float_format=float_format, na_rep=na_rep)
463 if buf is None:
464 return the_repr

pandas\core\series.pyc in _get_repr(self, name, print_header, length, na_rep, float_format)
481 string_index = index.format()
482
--> 483 maxlen = max(len(x) for x in string_index)
484 padSpace = min(maxlen, 60)
485

ValueError: max() arg is an empty sequence

@wesm

This comment has been minimized.

Copy link
Member

commented Dec 15, 2011

Not obvious what to_string should return in the case of an empty Series. What do you think? Could just default to:

In [4]: repr(s)
Out[4]: 'Series([], dtype=float64)'

Or it could return a length-0 string

@craustin

This comment has been minimized.

Copy link
Author

commented Dec 15, 2011

I'd say since repr returns Series([],... It could make sense to return that. The way we're using to_string, it'd make sense if it returned an empty string (if the newly-added "length" flag is false.

On Dec 14, 2011, at 11:34 PM, Wes McKinneyreply@reply.github.com wrote:

Not obvious what to_string should return in the case of an empty Series. What do you think? Could just default to:

In [4]: repr(s)
Out[4]: 'Series([], dtype=float64)'

Or it could return a length-0 string


Reply to this email directly or view it on GitHub:
https://github.com/wesm/pandas/issues/488#issuecomment-3156677

@wesm

This comment has been minimized.

Copy link
Member

commented Dec 15, 2011

Alright, I'm going with empty string (done in the above commit) :)

@wesm wesm closed this Dec 15, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.