question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BUG: int64 and uint64 values converted to float64 when concatenated

See original GitHub issue
  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Code Sample

import pandas as pd

pd.concat([
    pd.Series([1,2], dtype='uint64'),
    pd.Series([3,4], dtype='int64')
])

# Output:
0    1.0
1    2.0
0    3.0
1    4.0
dtype: float64

Problem description

The output datatype becomes float when the input datatypes are different integer types.

Since there are no NaN-values or decimals involved, it can be confusing that you suddenly get float output.

Expected Output

0    1
1    2
0    3
1    4
dtype: int64

union(int64, uint64) ⊆ int65, which is the same as int64 unless you have numbers close to “the edge”.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None python : 3.7.3.final.0 python-bits : 64 OS : Linux OS-release : 4.9.125-linuxkit machine : x86_64 processor : x86_64 byteorder : little LC_ALL : en_US.UTF-8 LANG : en_US.UTF-8 LOCALE : en_US.UTF-8

pandas : 0.25.0 numpy : 1.17.0 pytz : 2019.2 dateutil : 2.8.0 pip : 19.2.1 setuptools : 41.0.1 Cython : 0.29.13 pytest : None hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : None lxml.etree : 4.5.0 html5lib : None pymysql : None psycopg2 : None jinja2 : 2.10.1 IPython : 7.7.0 pandas_datareader: None bs4 : 4.8.0 bottleneck : None fastparquet : 0.3.2 gcsfs : None lxml.etree : 4.5.0 matplotlib : 3.1.1 numexpr : 2.6.9 odfpy : None openpyxl : None pandas_gbq : None pyarrow : None pytables : None s3fs : None scipy : 1.3.0 sqlalchemy : 1.3.6 tables : None xarray : None xlrd : 1.2.0 xlwt : None xlsxwriter : None

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:14 (10 by maintainers)

github_iconTop GitHub Comments

0reactions
jorisvandenbosschecommented, May 26, 2020

@bergkvist I am going to close this because the original issue (concatenating int64 and uint64 giving float64) is not something we are going to change (that discussion needs to happen in numpy, which there also already has been some).

But we can certainly further discuss the usability problems regarding unsigned integers in pandas, like the indexing you mentioned.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Converting unknown interface to float64 in Golang
Dave C has a good answer using reflect , and I'll compare that to type-by-type code below. First, to do what you were...
Read more >
How to Fix: You are trying to merge on object and int64 columns
The easiest way to fix this error is to simply convert the year variable in the second DataFrame to an integer and then...
Read more >
How to convert Int data type to Float in Golang? - GeeksforGeeks
Explanation: Firstly we declare a variable x of type int64 with a value of 5. Then we wrap x with float64(), which converts...
Read more >
Golang Types Tutorial | golangbot.com
Go support various types including boolean, float, integer, complex and string. This tutorial focuses on the usage of each type and also ...
Read more >
Solve 'You are trying to merge on object and int64 columns'
The error can occur in two scenarios, both when using merge or join in pandas. ... If you wish to proceed you should...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found