-
-
Notifications
You must be signed in to change notification settings - Fork 18k
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
RFE: a faster way to construct a pandas.Timestamp from an epoch time #14658
Comments
why would you do this in a loop? |
|
Because the whole data from the generator do not fit into memory? |
FYI @PyDeQ In [652]: %timeit pd.Timestamp.utcfromtimestamp(30)
The slowest run took 11.44 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 1.76 µs per loop vs In [653]: %timeit datetime.datetime.fromtimestamp(30, tz=datetime.timezone.utc)
The slowest run took 14.00 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 1.62 µs per loop But agreed with @jreback, you're much better off using vectorized methods in pandas. |
@TomAugspurger thanks. Unfortunately, |
Mind opening a PR to fix that? |
No promises but I can consider doing a PR in case of spare time, sure. |
#5218 seems to be the reason it's not in the API docs at the moment. |
Using just plain
And this one is documented (so I would prefer this over (and it also gives me the impression that the performance of |
@jorisvandenbossche, what document do you mean? So far, I've found only examples with strings as the first arguments and no |
pandas.to_datetime
called with anint
is too slow for my use case. Basically, I have a loop that sequentially gets an integer from a generator of about 1 000 000 numbers, converts it topandas.Timestamp
and passes it to a function. A profiler says that the call ofpandas.to_datetime
takes about 40 % of the total run time of my program.Compared to
datetime.datetime.fromtimestamp
, it's more than 60 times slower:Can you please provide/document a faster way to instantiate a
pandas.Timestamp
instance from an epoch time?The text was updated successfully, but these errors were encountered: