{"action":"created","issue":{"url":"https://api.github.com/repos/pydata/pandas/issues/9958","repository_url":"https://api.github.com/repos/pydata/pandas","labels_url":"https://api.github.com/repos/pydata/pandas/issues/9958/labels{/name}","comments_url":"https://api.github.com/repos/pydata/pandas/issues/9958/comments","events_url":"https://api.github.com/repos/pydata/pandas/issues/9958/events","html_url":"https://github.com/pydata/pandas/issues/9958","id":69692067,"number":9958,"title":"Left join on an integer column casts the column to float if it is in one of the indexes","user":{"login":"bembom","id":5873255,"avatar_url":"https://avatars.githubusercontent.com/u/5873255?v=3","gravatar_id":"","url":"https://api.github.com/users/bembom","html_url":"https://github.com/bembom","followers_url":"https://api.github.com/users/bembom/followers","following_url":"https://api.github.com/users/bembom/following{/other_user}","gists_url":"https://api.github.com/users/bembom/gists{/gist_id}","starred_url":"https://api.github.com/users/bembom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bembom/subscriptions","organizations_url":"https://api.github.com/users/bembom/orgs","repos_url":"https://api.github.com/users/bembom/repos","events_url":"https://api.github.com/users/bembom/events{/privacy}","received_events_url":"https://api.github.com/users/bembom/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/pydata/pandas/labels/Bug","name":"Bug","color":"e10c02"},{"url":"https://api.github.com/repos/pydata/pandas/labels/Difficulty%20Intermediate","name":"Difficulty Intermediate","color":"fbca04"},{"url":"https://api.github.com/repos/pydata/pandas/labels/Dtypes","name":"Dtypes","color":"e102d8"},{"url":"https://api.github.com/repos/pydata/pandas/labels/Effort%20Low","name":"Effort Low","color":"006b75"},{"url":"https://api.github.com/repos/pydata/pandas/labels/Reshaping","name":"Reshaping","color":"02d7e1"}],"state":"closed","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/pydata/pandas/milestones/32","html_url":"https://github.com/pydata/pandas/milestones/Next%20Major%20Release","labels_url":"https://api.github.com/repos/pydata/pandas/milestones/32/labels","id":933188,"number":32,"title":"Next Major Release","description":"after 0.18.0 of course","creator":{"login":"jreback","id":953992,"avatar_url":"https://avatars.githubusercontent.com/u/953992?v=3","gravatar_id":"","url":"https://api.github.com/users/jreback","html_url":"https://github.com/jreback","followers_url":"https://api.github.com/users/jreback/followers","following_url":"https://api.github.com/users/jreback/following{/other_user}","gists_url":"https://api.github.com/users/jreback/gists{/gist_id}","starred_url":"https://api.github.com/users/jreback/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jreback/subscriptions","organizations_url":"https://api.github.com/users/jreback/orgs","repos_url":"https://api.github.com/users/jreback/repos","events_url":"https://api.github.com/users/jreback/events{/privacy}","received_events_url":"https://api.github.com/users/jreback/received_events","type":"User","site_admin":false},"open_issues":962,"closed_issues":145,"state":"open","created_at":"2015-01-13T10:53:19Z","updated_at":"2016-06-12T21:04:41Z","due_on":"2016-08-31T04:00:00Z","closed_at":null},"comments":5,"created_at":"2015-04-20T22:05:38Z","updated_at":"2016-06-12T21:04:41Z","closed_at":"2016-06-12T21:04:40Z","body":"When I left-join two data frames on an int64 column, this column is cast to a float if it is the index of one of the two data frames:\r\n```python\r\n>>> id = [1, 143349558619761320]\r\n>>> a = pd.DataFrame({'a': [1, 2]}, index=pd.Int64Index(id, name='id'))\r\n>>> b = pd.DataFrame({'id': id[1], 'b': [2]})\r\n>>> merge_index = pd.merge(a, b, left_index=True, right_on='id', how='left')\r\n>>> print(merge_index.dtypes)\r\na       int64\r\nb     float64\r\nid    float64\r\ndtype: object\r\n```\r\nIn this case this is a problem because casting back to an int changes the value of this column:\r\n```python\r\n>>> int(float(143349558619761320))\r\n143349558619761312\r\n```\r\nIf the int64 column is not in the index, the column is not cast to a float: \r\n```python\r\n>>> merge_column = pd.merge(a.reset_index(), b, on='id', how='left')\r\n>>> print(merge_column.dtypes)\r\nid      int64\r\na       int64\r\nb     float64\r\ndtype: object\r\n```\r\nI understand that integer columns get cast to a float if NaNs are introduced (like column b here), but in this case the final column contains no missing values, so casting to a float can be avoided.\r\n\r\n\r\nOutput from pd.show_versions():\r\n\r\nINSTALLED VERSIONS\r\n------------------\r\ncommit: None\r\npython: 2.7.9.final.0\r\npython-bits: 64\r\nOS: Linux\r\nOS-release: 2.6.32-5-amd64\r\nmachine: x86_64\r\nprocessor: \r\nbyteorder: little\r\nLC_ALL: None\r\nLANG: en_US.UTF-8\r\n\r\npandas: 0.16.0\r\nnose: 1.3.4\r\nCython: None\r\nnumpy: 1.9.2\r\nscipy: 0.15.1\r\nstatsmodels: 0.6.1\r\nIPython: 3.0.0\r\nsphinx: None\r\npatsy: 0.3.0\r\ndateutil: 2.4.2\r\npytz: 2015.2\r\nbottleneck: None\r\ntables: 3.1.1\r\nnumexpr: 2.3.1\r\nmatplotlib: 1.4.3\r\nopenpyxl: None\r\nxlrd: None\r\nxlwt: None\r\nxlsxwriter: None\r\nlxml: None\r\nbs4: None\r\nhtml5lib: None\r\nhttplib2: None\r\napiclient: None\r\nsqlalchemy: None\r\npymysql: None\r\npsycopg2: None"},"comment":{"url":"https://api.github.com/repos/pydata/pandas/issues/comments/225460281","html_url":"https://github.com/pydata/pandas/issues/9958#issuecomment-225460281","issue_url":"https://api.github.com/repos/pydata/pandas/issues/9958","id":225460281,"user":{"login":"jreback","id":953992,"avatar_url":"https://avatars.githubusercontent.com/u/953992?v=3","gravatar_id":"","url":"https://api.github.com/users/jreback","html_url":"https://github.com/jreback","followers_url":"https://api.github.com/users/jreback/followers","following_url":"https://api.github.com/users/jreback/following{/other_user}","gists_url":"https://api.github.com/users/jreback/gists{/gist_id}","starred_url":"https://api.github.com/users/jreback/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jreback/subscriptions","organizations_url":"https://api.github.com/users/jreback/orgs","repos_url":"https://api.github.com/users/jreback/repos","events_url":"https://api.github.com/users/jreback/events{/privacy}","received_events_url":"https://api.github.com/users/jreback/received_events","type":"User","site_admin":false},"created_at":"2016-06-12T21:04:40Z","updated_at":"2016-06-12T21:04:40Z","body":"this is a dupe of #8596 which will be in 0.18.2\r\n\r\nsee http://pandas-docs.github.io/pandas-docs-travis/whatsnew.html#merging-changes"}}
{"actor":{"display_login":"jreback"}}