Skip to content

Slicing a Series returns an Array and fails #989

@jseabold

Description

@jseabold

From pystatsmodels ML "[pandas] slicing a series returns an array?"

Got it. It only happens if the series is longer than 200

x = pandas.Series(np.random.random(201), name='x')
x.reshape((-1,1))
<snip>

This is part of what I was talking about that Series aren't quite
array-like. Something like this

np.dot(x, np.random.random((1,10))

doesn't work, and I can't coerce x to be 2d. However, if X is less
than length 201, I sure can coerce it to be 2d, which is why I
couldn't reproduce

x = pandas.Series(np.random.random(199), name='x')
x = x.reshape((-1,1))

But I still can't dot

np.dot(x,np.random.random((1,10)))
<snip>
ValueError: The truth value of an array with more than one element is
ambiguous. Use a.any() or a.all()

I realize that trying to 'dot' might not make sense with a Series or
there's no intuitive interpretation to the output in terms of the
Series that I can think of offhand. Just an example of the 1d vs 2d
issue. Mainly, I guess I'd expect a series to be able to pass through
an atleast_2d check.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions