Skip to content

inconsistent behavior between DataFrame and Series when underlying objects are datetime #3320

Closed
@mirage007

Description

@mirage007

I just upgraded from 0.10 to to 0.10.1 to fix a previous issue I had, and i think I'm getting regressions or inconsistent behavior as it relates to issue #2627

the test below is a comparison on 0.10.0 and 0.10.1 under windows 32 bit python 2.7.2

import numpy
print numpy.__version__
import pandas
from pandas import DataFrame, Series
print pandas.__version__
import datetime

dt1d = [datetime.datetime(2013,1,1) + datetime.timedelta(days= i) for i in range(5)]
dtSeries = pandas.Series(dt1d)
print dtSeries.dtype
print dtSeries.apply(lambda x: x.date())
#this works
print [x.date() for x in dtSeries.values]

dt2d = [[datetime.datetime(2013,1,1) + datetime.timedelta(days= i)] for i in range(5)]
dtDf = DataFrame(dt2d)
print dtDf.dtypes
print dtDf.icol(0).apply(lambda x: x.date())
#the following do not work on 0.10.1 but work on 0.10.0
print [x.date() for x in dtDf.values[:,0]]
print [x.date() for x in dtDf.icol(0).values]

The output for 0.10.0 in ipython:

1.6.2
0.10.0
object
0 2013-01-01
1 2013-01-02
2 2013-01-03
3 2013-01-04
4 2013-01-05
[datetime.date(2013, 1, 1), datetime.date(2013, 1, 2), datetime.date(2013, 1, 3)
, datetime.date(2013, 1, 4), datetime.date(2013, 1, 5)]
0 object
0 2013-01-01
1 2013-01-02
2 2013-01-03
3 2013-01-04
4 2013-01-05
Name: 0
[datetime.date(2013, 1, 1), datetime.date(2013, 1, 2), datetime.date(2013, 1, 3)
, datetime.date(2013, 1, 4), datetime.date(2013, 1, 5)]
[datetime.date(2013, 1, 1), datetime.date(2013, 1, 2), datetime.date(2013, 1, 3)
, datetime.date(2013, 1, 4), datetime.date(2013, 1, 5)]

The output in 0.10.1:

1.6.2
0.10.1
object
0 2013-01-01
1 2013-01-02
2 2013-01-03
3 2013-01-04
4 2013-01-05
[datetime.date(2013, 1, 1), datetime.date(2013, 1, 2), datetime.date(2013, 1, 3)
, datetime.date(2013, 1, 4), datetime.date(2013, 1, 5)]
0 datetime64[ns]
0 2013-01-01
1 2013-01-02
2 2013-01-03
3 2013-01-04
4 2013-01-05

Name: 0

AttributeError Traceback (most recent call last)
in ()
18 print dtDf.icol(0).apply(lambda x: x.date())
19 #the following do not work on 0.10.1 but work on 0.10.0
---> 20 print [x.date() for x in dtDf.values[:,0]]
21 print [x.date() for x in dtDf.icol(0).values]

AttributeError: 'numpy.datetime64' object has no attribute 'date'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions