-
Notifications
You must be signed in to change notification settings - Fork 679
Propose more robust datetime to unix time conversion in yahoo/daily.py #378
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
Comments
Corrected snippet to include self...
|
This would resolve the error one gets when trying to pull data pre-1970 (on a Windows machine):
I think this would also work:
|
@shipmints EPOCH should in fact be so we may wonder what will happen if What ever change in pandas-datareader code will be... we should have
Calculating difference between 2 datetime with differents timezone (according DST or not ...) may be a bit tricky (but some Python library can do this) With Python 3.6 and Pandas 0.20 there is a very convenient method: pd.Timestamp('1970-01-01', tz='UTC').timestamp() unfortunately not with Python 2.7 and same Pandas version |
A workaround may be to define (probably in def _timestamp(ts):
"""
Return unix timestamp for Pandas Timestamp ts
See https://github.com/pandas-dev/pandas/issues/17329
"""
try:
return ts.timestamp()
except AttributeError:
return ts.value // 1000 / 1000000.0 With Python 3.6 (same result with Python 2.7) In [161]: _timestamp(pd.Timestamp("1970-1-1", tz="UTC"))
Out[161]: 0.0
In [162]: _timestamp(pd.Timestamp("1970-1-1", tz="US/Central"))
Out[162]: 21600.0
In [163]: _timestamp(pd.Timestamp("1970-1-1", tz="Europe/Paris"))
Out[163]: -3600.0 |
but the problem of this code is that it returns a different value when no timezone is given With Python 3.6 (my system timezone is Europe/Paris) In [167]: _timestamp(pd.Timestamp("1970-1-1"))
Out[167]: -3600.0 with Python 2.7 In [43]: _timestamp(pd.Timestamp("1970-1-1"))
Out[43]: 0.0 |
Maybe def _timestamp(ts):
"""
Return unix timestamp for Timestamp ts
See https://github.com/pandas-dev/pandas/issues/17329
"""
try:
return ts.timestamp()
except AttributeError:
timestamp = ts.value // 1000 / 1000000.0
if ts.tz is None:
timestamp += time.timezone
return timestamp
In [36]: _timestamp(pd.Timestamp("1970-1-1", tz="UTC"))
Out[36]: 0.0
In [37]: _timestamp(pd.Timestamp("1970-1-1", tz="US/Central"))
Out[37]: 21600.0
In [38]: _timestamp(pd.Timestamp("1970-1-1", tz="Europe/Paris"))
Out[38]: -3600.0
In [69]: _timestamp(pd.Timestamp("1970-1-1")) # use local timezone
Out[69]: -3600.0 |
@jreback Should this be considered a bug? Can't download pre-1970 data from Yahoo even when it is available (on Windows machines). |
the patch by @femtotrader looks fine if u want to submit a PR with tests |
Yahoo has been deprecated. |
I don't think this was ever implemented in yahoo, which is no longer deprecated. I can do a PR if needed. @femtotrader - were you suggesting that that
@bashtage - thoughts? |
To be clear,
raises a Also, since yahoo only returns daily data, how important is the time zone issue? Seems like tz could safely be ignored. |
Doesn't seem like a high priority issue, but if you have some time and want to fix... |
Was this improved with #703 ? |
Apologies as I'm new to git and github. I can try to make a fork/patch/pull request but I have to figure out how. In the meantime, I thought I'd offer the following to the local experts who surely can do this an order of magnitude faster than I can...
The text was updated successfully, but these errors were encountered: