Skip to content
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

Apply datetime methods to timestamps results in numpy errors #2689

Closed
NigelCleland opened this issue Jan 14, 2013 · 2 comments
Closed

Apply datetime methods to timestamps results in numpy errors #2689

NigelCleland opened this issue Jan 14, 2013 · 2 comments
Assignees
Labels
Bug Datetime Datetime data dtype
Milestone

Comments

@NigelCleland
Copy link

Hi,

This may or may not be a bug. I'm unsure of which functionality you were intending.

I have a timestamp created by

rng = pd.date_range(start_date, periods = 100, freq='2H')
A = DataFrame(rng) # We'll leave it as a generic index for now, not important.

I then have a function which is applied to that dataframe via A.apply(f)

def f(x):
    return (x.hour, x.day, x.month)

if I apply this functionality to the raw dataframe via .apply, this will result in a numpy.datetime64 error.

However, if I apply it to individual points.

E.g. f(A.ix[10]), then the correct functionality results.

I have determined that this is due to a difference between the types of the two

e.g. A.dtype = dtype('datetime64[n]s')

type(A.ix[10]) = pandas.tslib.Timestamp

Thus to get around the issue above you may simply add the following functionality to the function

def f(x):
x = pd.Timestamp(x)
return (x.hour, x.month, x.year)

I am filing this as I'm unsure of what you're intended functionality is with this matter

@ghost ghost assigned wesm Jan 19, 2013
@wesm
Copy link
Member

wesm commented Jan 20, 2013

Taking a look at this. A guideline for future posting issues: make sure the code you post works (there were multiple typos, I fixed a couple of them) and the exact code that generated the error is listed

@wesm
Copy link
Member

wesm commented Jan 20, 2013

fixed along with #2627

@wesm wesm closed this as completed Jan 20, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Datetime Datetime data dtype
Projects
None yet
Development

No branches or pull requests

2 participants