Skip to content

DatetimeIndex values returns the wrong values #1802

Closed
jacoblsmith opened this Issue Aug 22, 2012 · 3 comments

3 participants

@jacoblsmith

When I try to use the values method for a DatetimeIndex, I get the wrong values.

import pandas as pd
index = pd.date_range('2000-1-1',periods=24,freq='MS')
print 'Version:', pd.version
print '\nIndex:',index
print '\nValues:',index.values
print '\nReal Values:',[ i for i in index]

Version: 0.8.2.dev-c99d9cd

Index:
[2000-01-01 00:00:00, ..., 2001-12-01 00:00:00]
Length: 24, Freq: MS, Timezone: None

Values: [1970-01-11 184:00:00 1970-01-11 160:00:00 1970-01-12 152:00:00
1970-01-12 128:00:00 1970-01-12 80:00:00 1970-01-12 56:00:00
1970-01-12 08:00:00 1970-01-12 240:00:00 1970-01-12 216:00:00
1970-01-12 168:00:00 1970-01-12 144:00:00 1970-01-12 96:00:00
1970-01-12 72:00:00 1970-01-12 48:00:00 1970-01-12 208:00:00
1970-01-12 184:00:00 1970-01-12 136:00:00 1970-01-12 112:00:00
1970-01-12 64:00:00 1970-01-12 40:00:00 1970-01-12 16:00:00
1970-01-12 224:00:00 1970-01-12 200:00:00 1970-01-12 152:00:00]

Real Values: [, , , , , , , , ,, , , , , , , , , , , , , , ]

@lodagro
Python for Data member
lodagro commented Aug 22, 2012

see also #1779

@jacoblsmith

My apologies, I missed this when searching for datetimeindex and values.

This is probably not the most elegant solution, but I added the following to the DatetimeIndex

@property
def values(self):
return np.asarray([self[i] for i in range(len(self))])

@wesm
Python for Data member
wesm commented Aug 22, 2012

I wouldn't do that if I were you. The display bug you're seeing is only on the NumPy (1.6.x) side and can be safely ignored. If you want an array of datetime objects use 'asobject' or 'to_pydatetime()'

@wesm wesm closed this Aug 22, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.