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

BUG: check if a collections.Sequence on printing #3240

Closed
jreback opened this issue Apr 2, 2013 · 9 comments
Closed

BUG: check if a collections.Sequence on printing #3240

jreback opened this issue Apr 2, 2013 · 9 comments
Labels
Bug Output-Formatting __repr__ of pandas objects, to_string Testing pandas testing functions or related to the test suite

Comments

@jreback
Copy link
Contributor

jreback commented Apr 2, 2013

@ghost
Copy link

ghost commented Apr 2, 2013

related #3000, #3005 , it's a general pattern, ABCs did not see heavy use when pandas
was in it's formative stage and so it's type-directed behaviour is too strict.

@jreback
Copy link
Contributor Author

jreback commented Apr 2, 2013

yep....also need to accept this in the constructors (as well as output-formatters)

maybe should have a function to basically do the test isinstance(obj,list)
(which sometimes needs a tuple sometimes not), so maybe modify
_is_sequence_like a bit

@ghost
Copy link

ghost commented Apr 2, 2013

the opt-in register() mechanism of the ABCs is pretty useful, just need
to be careful of sharp corners: strings are sequences of-course, also #2978

@jreback
Copy link
Contributor Author

jreback commented Apr 2, 2013

actually this is a bit more complicated, the problem is that a Timestamp is a sequence as well! (and we often have to do some checking to avoid treating it like a list); np.scalar I think should be redefined a bit (there is a routine somewhere in the cython code to do scalar testing in any event...should be fixed/consolidated as well)

@ghost
Copy link

ghost commented Apr 2, 2013

what?! how is Timestamp a sequence?

In [39]: t=Timestamp("2000-1-1")

In [40]: t[0]
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-40-d0a24a012877> in <module>()
----> 1 t[0]

TypeError: 'Timestamp' object does not support indexing

In [41]: list(t)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-41-f57fd3c9bd0b> in <module>()
----> 1 list(t)

TypeError: 'Timestamp' object is not iterable

In [42]: import collections

In [43]: isinstance(t,collections.Sequence)
Out[43]: False

@jreback
Copy link
Contributor Author

jreback commented Apr 2, 2013

sorry...meant that it isn't a scalar (though we treat it like one)

In [4]: np.isscalar(1)
Out[4]: True

In [5]: np.isscalar(pd.Timestamp('20010101'))
Out[5]: False

@jtratner
Copy link
Contributor

jtratner commented Sep 5, 2013

@jreback maybe this is silly, but why is the way that it prints actually wrong? Is there another example where this would matter? [clearly, I'm going through earlier bug reports]

@jreback
Copy link
Contributor Author

jreback commented Sep 5, 2013

no the issue here is this

is you have a list of lists then the DataFrame constructor works fine

but if its a list-of-sequencers that are not lists but act like lists (eg collections.Sequence) then it doesn't work

this used to work when we used np.asarray but for various reasons the conversions are now a bit more 'manual'

so this is actually pretty easy to just accept a collections.Sequence in the constructors

@jreback jreback modified the milestones: 0.15.0, 0.14.0 Feb 18, 2014
@jreback jreback modified the milestones: 0.16.0, 0.17.0 Jan 26, 2015
@WillAyd
Copy link
Member

WillAyd commented Jul 6, 2018

Closed due to age and ambiguity. If there is a reproducible example for issue feel free to reopen

@WillAyd WillAyd closed this as completed Jul 6, 2018
@WillAyd WillAyd modified the milestones: Contributions Welcome, No action Jul 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Output-Formatting __repr__ of pandas objects, to_string Testing pandas testing functions or related to the test suite
Projects
None yet
Development

No branches or pull requests

3 participants