Skip to content

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

@ProgrammingDao

Description

@ProgrammingDao

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions