{"action":"opened","issue":{"url":"https://api.github.com/repos/Blosc/bcolz/issues/361","repository_url":"https://api.github.com/repos/Blosc/bcolz","labels_url":"https://api.github.com/repos/Blosc/bcolz/issues/361/labels{/name}","comments_url":"https://api.github.com/repos/Blosc/bcolz/issues/361/comments","events_url":"https://api.github.com/repos/Blosc/bcolz/issues/361/events","html_url":"https://github.com/Blosc/bcolz/issues/361","id":280083356,"number":361,"title":"ctable.fromdataframe doesn't preserve datetime indices.","user":{"login":"Kyrish","id":473753,"avatar_url":"https://avatars2.githubusercontent.com/u/473753?v=4","gravatar_id":"","url":"https://api.github.com/users/Kyrish","html_url":"https://github.com/Kyrish","followers_url":"https://api.github.com/users/Kyrish/followers","following_url":"https://api.github.com/users/Kyrish/following{/other_user}","gists_url":"https://api.github.com/users/Kyrish/gists{/gist_id}","starred_url":"https://api.github.com/users/Kyrish/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kyrish/subscriptions","organizations_url":"https://api.github.com/users/Kyrish/orgs","repos_url":"https://api.github.com/users/Kyrish/repos","events_url":"https://api.github.com/users/Kyrish/events{/privacy}","received_events_url":"https://api.github.com/users/Kyrish/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-12-07T10:48:55Z","updated_at":"2017-12-07T10:48:55Z","closed_at":null,"author_association":"NONE","body":"Let's consider following case:\r\n\r\n```python\r\ndate_range = pd.date_range(start='2017-01-01', end='2017-01-03', freq='D')\r\ncols = ['A', 'B', 'C', 'D', 'E']\r\ndf = pd.DataFrame(index=date_range, data=np.random.rand(len(date_range), len(cols)), columns=cols)\r\ndf\r\n```\r\n| A | B | C | D | E |\r\n| - | - | - | - | - |\r\n| 2017-01-01 | 0.140845 | 0.619423 | 0.697564 | 0.975552 | 0.419815 |\r\n| 2017-01-02 | 0.327959 | 0.657860 | 0.234037 | 0.705020 | 0.656515 |\r\n| 2017-01-03 | 0.065697 | 0.543179 | 0.517165 | 0.692339 | 0.340754 |\r\n\r\n```python\r\ndf_table = bcolz.ctable.fromdataframe(df)\r\ndf_table\r\n```\r\n\r\n```\r\nctable((3,), [('A', '<f8'), ('B', '<f8'), ('C', '<f8'), ('D', '<f8'), ('E', '<f8')])\r\n  nbytes: 120; cbytes: 80.00 KB; ratio: 0.00\r\n  cparams := cparams(clevel=5, shuffle=1, cname='blosclz', quantize=0)\r\n[( 0.14084531,  0.61942324,  0.69756392,  0.9755517,  0.41981526)\r\n ( 0.3279591,  0.65785982,  0.23403727,  0.70502042,  0.65651498)\r\n ( 0.06569704,  0.54317941,  0.51716506,  0.69233858,  0.34075387)]\r\n```\r\n\r\nand if we try to retrieve dataframe from table we get:\r\n\r\n```python\r\ndf_ = df_table.todataframe()\r\ndf_\r\n```\r\n\r\n| A | B | C | D | E |\r\n| - | - | - | - | - |\r\n| 0 | 0.140845 | 0.619423 | 0.697564 | 0.975552 | 0.419815 |\r\n| 1 | 0.327959 | 0.657860 | 0.234037 | 0.705020 | 0.656515 |\r\n| 2 | 0.065697 | 0.543179 | 0.517165 | 0.692339 | 0.340754 |\r\n\r\nA possible workaround is to duplicate index column to regular one:\r\n```python\r\ndf['_index'] = df.index\r\ndf_table = bcolz.ctable.fromdataframe(df)\r\ndf_table.attrs['_index'] = '_index'\r\n```\r\n\r\nIn this case, Bcolz preserves datetime type. And after retrieving you can assign your index back.\r\n"}}
{"actor":{"display_login":"Kyrish"}}