Skip to content

pd.concat(objs) drops type of the inputs if all inputs are empty #7024

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
OlexiyO opened this issue May 1, 2014 · 3 comments
Closed

pd.concat(objs) drops type of the inputs if all inputs are empty #7024

OlexiyO opened this issue May 1, 2014 · 3 comments

Comments

@OlexiyO
Copy link

OlexiyO commented May 1, 2014

When concatenating several pd.Series of the same type, I would expect the output Series to have the same type. However, this does not hold if all input Series are empty:

In [0]: x = pd.Series([], dtype=int)
In [1]: pd.concat([x, x])
Series([], dtype: object)

How I would expect it to work:
pd.concat([x, x]) should return Series([], dtype=int)

Just as an example, this works fine:

In [2]: y = pd.Series([1], dtype=int)
In [3]: pd.concat([y, y])  # This works fine:
0    1
0    1
dtype: int64
@cpcloud
Copy link
Member

cpcloud commented May 1, 2014

Are you sure that's the correct example? The first x is not empty. In any event, what's the use case here? Why do you care about the dtype of an empty array?

@jreback
Copy link
Contributor

jreback commented May 1, 2014

this is fixed in master/0.14 by #5742

In [5]: x = Series([],dtype=int)

In [6]: concat([x,x])
Out[6]: Series([], dtype: int64)

In [7]: x = Series([],dtype=float)

In [8]: concat([x,x])
Out[8]: Series([], dtype: float64)

@jreback jreback closed this as completed May 1, 2014
@OlexiyO
Copy link
Author

OlexiyO commented May 1, 2014

Are you sure that's the correct example? The first x is not empty.
Ouch, sorry about this. I've updated the original example -- it should be

x = pd.Series([], dtype=int)

Why do you care about the dtype of an empty array?
Because some further code may depend on the array having a certain type.

this is fixed in master/0.14
Thanks, jreback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants