← All tasks
pythonranaroussi/yfinance #937Not a task: already works

Ticker.history: history's index is not of type DateTimeIndex when dividend and split tables are empty

envgap__ranaroussi__yfinance-937

01 / FAILURE SIGNATURE

As reported upstream

E       AttributeError: 'Index' object has no attribute 'tz_localize'
Not a benchmark task.
  • The project already builds and runs before the fix, so there is nothing to repair.

02 / ENVIRONMENT RECIPE

Base commit
24e348e0e41b8c78e2418775ab4d4d4ed5bff4eb
Manifest
requirements.txt
Reproduce
Awaiting issue-specific recipe
Run under trace
Awaiting a meaningful runtime command

03 / ORIGINAL ISSUE TEXT

ranaroussi/yfinance #937 · read the original issue
**Issue**:



Ticker.history (line 295):

>       df.index = df.index.tz_localize("UTC").tz_convert(data["chart"]["result"][0]["meta"]["exchangeTimezoneName"])

E       AttributeError: 'Index' object has no attribute 'tz_localize'



**Reason**: 



During the concatenation of a proper price table with empty dividend and split tables, the price table's index has changed from _pandas.DatetimeIndex_ to _pandas.Index_ because the empty tables had this index type.



**Proposed solution**: 



Modify _parse_actions_ (in utils.py) to initialise the dividend and split tables with : 

`dividends = _pd.DataFrame(columns=["Dividends"], index=_pd.DatetimeIndex([]))`

 `splits = _pd.DataFrame(columns=["Stock Splits"], index=_pd.DatetimeIndex([]))`





Local modules' versions:



finance : 0.1.69

pandas : 1.4.0

python : 3.10

Continue on GitHub ↗

04 / LABELS

Labels from the report text only; not yet run

No supported category has been assigned.

Label rules and the text that matched
[]