DatetimeIndex values returns the wrong values #1802

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

Comments

Projects
None yet
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: <class 'pandas.tseries.index.DatetimeIndex'>
[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: [<Timestamp: 2000-01-01 00:00:00>, <Timestamp: 2000-02-01 00:00:00>, <Timestamp: 2000-03-01 00:00:00>, <Timestamp: 2000-04-01 00:00:00>, <Timestamp: 2000-05-01 00:00:00>, <Timestamp: 2000-06-01 00:00:00>, <Timestamp: 2000-07-01 00:00:00>, <Timestamp: 2000-08-01 00:00:00>, <Timestamp: 2000-09-01 00:00:00>,<Timestamp: 2000-10-01 00:00:00>, <Timestamp: 2000-11-01 00:00:00>, <Timestamp:2000-12-01 00:00:00>, <Timestamp: 2001-01-01 00:00:00>, <Timestamp: 2001-02-01 00:00:00>, <Timestamp: 2001-03-01 00:00:00>, <Timestamp: 2001-04-01 00:00:00>, <Timestamp: 2001-05-01 00:00:00>, <Timestamp: 2001-06-01 00:00:00>, <Timestamp: 2001-07-01 00:00:00>, <Timestamp: 2001-08-01 00:00:00>, <Timestamp: 2001-09-01 00:00:00>, <Timestamp: 2001-10-01 00:00:00>, <Timestamp: 2001-11-01 00:00:00>, <Timestamp: 2001-12-01 00:00:00>]

@lodagro

This comment has been minimized.

Show comment
Hide comment
@lodagro

lodagro Aug 22, 2012

Contributor

see also #1779

Contributor

lodagro commented Aug 22, 2012

see also #1779

@jacoblsmith

This comment has been minimized.

Show comment
Hide comment
@jacoblsmith

jacoblsmith Aug 22, 2012

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))])

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

This comment has been minimized.

Show comment
Hide comment
@wesm

wesm Aug 22, 2012

Member

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()'

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