Skip to content

Dataframe with incorrect index type returned when combining two tickers (one without data) #1382

Closed

Description

@btodac
import yfinance as yf
df = yf.download( tickers = ["^NDX", "^TWII"],       
                  start="2023-01-22", end="2023-01-29",
                  interval = "1m",
                  group_by = 'column',
                  auto_adjust = False,
                  prepost = True,
                  threads = True,
                  proxy = None
                  )
[*********************100%***********************]  2 of 2 completed

1 Failed download:
- ^TWII: No data found for this date range, symbol may be delisted

It's not delisted, it's just there as there is no data due to the lunar new year.
The problem is the returned dataframe index is not a datetime index, but has type object)

yfinace version 0.2.9, python 3.10.8 on Linux ubuntu

Activity

  1. asafravid commented on Feb 1, 2023

    @asafravid
    Collaborator

    What happens with other dates?

  2. ValueRaider commented on Feb 1, 2023

    @ValueRaider
    Collaborator

    @asafravid Not helpful.

    This appears to be a simple problem for someone to debug & fix, clue is one ticker doesn't return data so maybe messing up merge.

  3. asafravid commented on Feb 1, 2023

    @asafravid
    Collaborator

    I’ll check

  4. btodac commented on Feb 2, 2023

    @btodac
    Author

    I had a look at this myself. Pandas concat now combines the empty dataframe and then fails to convert the timezone. I altered a try catch block in multi.py at line 155 to remove the empty dataframe and then everything seemed to work fine:

    try:
            dfs = dict([(key, df) for key, df in shared._DFS.items() if not df.empty])
            data = _pd.concat(dfs.values(), axis=1, sort=True,
                              keys=dfs.keys())
        except Exception:
            _realign_dfs()
            data = _pd.concat(shared._DFS.values(), axis=1, sort=True,
                              keys=shared._DFS.keys())
    
  5. asafravid commented on Feb 2, 2023

    @asafravid
    Collaborator

    Can you create a PR?

  6. ValueRaider commented on Feb 2, 2023

    @ValueRaider
    Collaborator

    remove the empty dataframe

    Is this best solution? My concern is users might think yfinance is failing to fetch and post Issues.

  7. DogInfantry commented on Jul 8, 2026

    @DogInfantry
    Contributor

    @
    Looks resolved on dev. reindex_dfs now builds the union index only from non-empty frames, then reindexes the empty ticker onto it. Combining a populated 1m frame with a data-less ticker (utils.empty_df()) yields a DatetimeIndex (datetime64[us]), not an object index, so the concatenated result keeps a proper datetime index. Appears safe to close.
    @

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions