Skip to content

Timestamp.now() throws an Error #5339

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
jankatins opened this issue Oct 26, 2013 · 9 comments · Fixed by #5342
Closed

Timestamp.now() throws an Error #5339

jankatins opened this issue Oct 26, 2013 · 9 comments · Fixed by #5342
Labels
API Design Datetime Datetime data dtype
Milestone

Comments

@jankatins
Copy link
Contributor

Not sure if that is expected, but if it is expected it would be nice if the error message and the docsring of Timestamp.now() could be improved.

from pandas.tslib import Timestamp
Timestamp.now()

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-45-634034a47269> in <module>()
----> 1 Timestamp.now()

C:\portabel\Python27\lib\site-packages\pandas\tslib.pyd in pandas.tslib.Timestamp.__new__ (pandas\tslib.c:5167)()

TypeError: __new__() takes at most 5 positional arguments (9 given)
@cancan101
Copy link
Contributor

Timestamp.today() raises the same exception.

@jtratner
Copy link
Contributor

Trivial implementations of this would just need to add these to the Cython
Timestamp (NOT to the _timestamp class). Not sure if time.time() is
actually accurate enough.

cdef now(self):
    return Timestamp(time.time() * 1e9)

cdef today(self):
    return Timestamp(datetime.today())

@jankatins
Copy link
Contributor Author

It would also be nice if Timestamp.__float__() (probably simple setting __float__ = toordinal) could be implemented. That would make some special casing in https://github.com/yhat/ggplot/blob/master/ggplot/geoms/geom_density.py unnecessary.

@jtratner
Copy link
Contributor

@JanSchulz care to take a stab at it? I don't think Cython will let you do __float__ = toordinal like that, so you'd probably need to define as:

cdef __float__(self):
     return self.toordinal()

@jreback
Copy link
Contributor

jreback commented Oct 26, 2013

@JanSchulz __float__ IMHO should raise, this is not an automatic conversion, with the ambiguity of the units, Timestamp.value is your best bet (in ns from epoch)

@cpcloud
Copy link
Member

cpcloud commented Oct 27, 2013

Arent these class methods in datetime? Also u can call datetime.now instead
of calling time.time

On Saturday, October 26, 2013, jreback wrote:

@JanSchulz https://github.com/JanSchulz float IMHO raise, this is
not an automatic conversion, with the ambiguity of the units,
Timestamp.value is your best bet (in ns from epoch)


Reply to this email directly or view it on GitHubhttps://github.com//issues/5339#issuecomment-27154028
.

Best,
Phillip Cloud

@cancan101
Copy link
Contributor

@cpcloud I think @jreback's solution was to have the class methods for Timestamp call down to the class methods for datetime and then to pass the resulting datetime object to the Timestamp constructor.

@jtratner
Copy link
Contributor

datetime.now() has less resolution than time.time() right?

@cpcloud
Copy link
Member

cpcloud commented Oct 27, 2013

The precision of time is system dependent. The class method now, for
example, should return the same thing as Timestamp('now').

On Sunday, October 27, 2013, Jeff Tratner wrote:

datetime.now() has less resolution than time.time() right?


Reply to this email directly or view it on GitHubhttps://github.com//issues/5339#issuecomment-27175693
.

Best,
Phillip Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Datetime Datetime data dtype
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants