Skip to content

BUG: frame creation with multi-index and tuples in dict #10863

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
ruidc opened this issue Aug 20, 2015 · 4 comments · Fixed by #30646
Closed

BUG: frame creation with multi-index and tuples in dict #10863

ruidc opened this issue Aug 20, 2015 · 4 comments · Fixed by #30646
Labels
good first issue Needs Tests Unit test(s) needed to prevent regressions
Milestone

Comments

@ruidc
Copy link
Contributor

ruidc commented Aug 20, 2015

In [1]: import pandas;import numpy;import datetime;
In [2]: v = datetime.date.today()
In [3]: pandas.DataFrame({v : pandas.Series(range(3),index=range(3))}, columns=[v])
Out[3]:
   2015-08-20
0           0
1           1
2           2
In [4]: v = v, v
In [5]: pandas.DataFrame({v : pandas.Series(range(3),index=range(3))}, columns=[v])
Out[5]:
  (2015-08-20, 2015-08-20)
0                      NaN
1                      NaN
2                      NaN
@jreback jreback changed the title Bug with Dates in index BUG: frame creation with multi-index and tuples in dict Aug 20, 2015
@jreback jreback added Bug Prio-low Reshaping Concat, Merge/Join, Stack/Unstack, Explode MultiIndex labels Aug 20, 2015
@jreback jreback modified the milestones: 0.17.0, Next Major Release Aug 20, 2015
@kawochen
Copy link
Contributor

kawochen commented Sep 8, 2015

See #7888

use datetime.datetime.combine(datetime.date.today(), datetime.time()) instead of datetime.date.today()

@jreback
Copy link
Contributor

jreback commented Sep 8, 2015

yep, so the issue is with the datetime.date, which is mostly unsupported.

In [9]: v = Timestamp.today().normalize()

In [10]: v
Out[10]: Timestamp('2015-09-08 00:00:00')

In [11]: pandas.DataFrame({v : pandas.Series(range(3),index=range(3))}, columns=[v])
Out[11]: 
   2015-09-08
0           0
1           1
2           2

In [12]: v = v, v                                                                   

In [13]: pandas.DataFrame({v : pandas.Series(range(3),index=range(3))}, columns=[v])
Out[13]: 
   (2015-09-08 00:00:00, 2015-09-08 00:00:00)
0                                           0
1                                           1
2                                           2

@n8henrie
Copy link

n8henrie commented Feb 21, 2018

I assume I am running into this same issue -- multiindex with pd.Timestamp.date() in a tuple results in all NaN, pd.Timestamp works fine.

Examples below don't have anything else in the tuple to simplify demonstration of the issue, but my use case obviously has other stuff there.

In [3]: pd.DataFrame({'foo': {(pd.Timestamp(2017, 10, 5).date(),): 21.0}})
Out[3]:
            foo
2017-10-05  NaN

In [4]: pd.DataFrame({'foo': {(pd.Timestamp(2017, 10, 5),): 21.0}})
Out[4]:
            foo
2017-10-05  21.0

I can go into detail on my use case if it were helpful, but it's basically looking at employee productivity per shift, where each day (part 0 of the index) has several shifts (part 1 of the index).

For now, using Timestamp.normalize() seems to be a workaround, even though putting all the events at 00:00 seems a little strange.

@mroeschke
Copy link
Member

The issue works on master. Could use a test.

In [34]: In [4]: v = v, v
    ...: In [5]: pandas.DataFrame({v : pandas.Series(range(3),index=range(3))}, columns=[v])
Out[34]:
   (2019-10-13, 2019-10-13)
0                         0
1                         1
2                         2

In [35]: pd.__version__
Out[35]: '0.26.0.dev0+555.gf7d162b18'

@mroeschke mroeschke added good first issue Needs Tests Unit test(s) needed to prevent regressions and removed Bug Difficulty Intermediate MultiIndex Reshaping Concat, Merge/Join, Stack/Unstack, Explode labels Oct 13, 2019
@simonjayhawkins simonjayhawkins modified the milestones: Contributions Welcome, 1.0 Jan 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Needs Tests Unit test(s) needed to prevent regressions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants