Skip to content

When a series contains all strings, converting to dtype "int" generates bogus int values #1987

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
lbeltrame opened this issue Sep 28, 2012 · 3 comments
Labels
Milestone

Comments

@lbeltrame
Copy link
Contributor

This works:

In [3]: series = pandas.Series(["car", "house", "tree", 1])

In [4]: series
Out[4]: 
0      car
1    house
2     tree
3        1

In [5]: series.astype("int")
ValueError: invalid literal for long() with base 10: 'tree'

This doesn't:

In [7]: series = pandas.Series(["car", "house", "tree","1"])

In [8]: series.astype("int")
Out[8]: 
0                  0
1           44735616
2    139883221510192
3                  1

This with RC2 state from git.

@wesm
Copy link
Member

wesm commented Sep 28, 2012

That's no good. I'll look into it

@wesm
Copy link
Member

wesm commented Sep 29, 2012

Irritating NumPy brokenness:

In [3]: arr = np.array(["car", "house", "tree","1"], dtype=object)

In [4]: arr
Out[4]: array([car, house, tree, 1], dtype=object)

In [5]: arr.astype(int)
Out[5]: array([4454445056, 4454445056, 4482056920,          1])

@wesm wesm closed this as completed in 48fadc1 Sep 29, 2012
@makmanalp
Copy link
Contributor

For posterity, if you hit this message and arrive here through the helpful bug id in the backtrace, (long-fixed bug aside) it means you're trying to convert something into an int that can't be converted into an int, and the error message is telling you the exact thing that failed: invalid literal for int() with base 10: blablabla. Don't be a bonehead like me, and read the error message instead. :-)

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

No branches or pull requests

3 participants