SimFin / simfin

Simple financial data for Python
https://simfin.com/
Other
299 stars 39 forks source link

Bug Report: pandas.errors.InvalidIndexError: Reindexing only valid with uniquely valued Index objects for 'growth_signals()' #27

Closed odb9402 closed 6 months ago

odb9402 commented 6 months ago

Bug Report

Description

During following up the tutorial in here, I got the error, pandas.errors.InvalidIndexError: Reindexing only valid with uniquely valued Index objects, in sf.StockHub.growth_signals(variant='daily').

Similar issue here: https://github.com/SimFin/simfin/issues/26

System Details

Code Example

   # Copied from the Simfin tutorial

    import simfin as sf

    # Configure simfin.
    sf.set_data_dir('~/simfin_data/')
    sf.load_api_key(path='~/simfin_api_key.txt', default_key='free')

    market = 'us'

    offset = pd.DateOffset(days=60)

    refresh_days = 0
    refresh_days_shareprices = 10

    hub = sf.StockHub(market=market, offset=offset,
                      refresh_days=refresh_days,
                      refresh_days_shareprices=refresh_days_shareprices)

    df_growth_signals = hub.growth_signals(variant='daily') # Error here
    df_fin_signals = hub.fin_signals(variant='daily')
    df_val_signals = hub.val_signals(variant='daily')

    dfs = [df_fin_signals, df_growth_signals, df_val_signals]
    df_signals = pd.concat(dfs, axis=1)

Result / Error

(base) dongpinoh@Dongpinui-MacBookPro pinsfund % python test.py
/Users/dongpinoh/anaconda3/lib/python3.11/site-packages/pandas/core/arrays/masked.py:60: UserWarning: Pandas requires version '1.3.6' or newer of 'bottleneck' (version '1.3.5' currently installed).
  from pandas.core import (
Dataset "us-income-ttm" on disk (0 days old).
- Downloading ... 100.0%
- Extracting zip-file ... Done!
/Users/dongpinoh/anaconda3/lib/python3.11/site-packages/simfin/load.py:154: FutureWarning: The argument 'date_parser' is deprecated and will be removed in a future version. Please use 'date_format' instead, or read your data in as 'object' dtype and then call 'to_datetime'.
  df = pd.read_csv(path, sep=';', header=0,
- Loading from disk ... Done!
Dataset "us-income-quarterly" on disk (0 days old).
- Downloading ... 100.0%
- Extracting zip-file ... Done!
/Users/dongpinoh/anaconda3/lib/python3.11/site-packages/simfin/load.py:154: FutureWarning: The argument 'date_parser' is deprecated and will be removed in a future version. Please use 'date_format' instead, or read your data in as 'object' dtype and then call 'to_datetime'.
  df = pd.read_csv(path, sep=';', header=0,
- Loading from disk ... Done!
Dataset "us-balance-ttm" on disk (0 days old).
- Downloading ... 100.0%
- Extracting zip-file ... Done!
/Users/dongpinoh/anaconda3/lib/python3.11/site-packages/simfin/load.py:154: FutureWarning: The argument 'date_parser' is deprecated and will be removed in a future version. Please use 'date_format' instead, or read your data in as 'object' dtype and then call 'to_datetime'.
  df = pd.read_csv(path, sep=';', header=0,
- Loading from disk ... Done!
Dataset "us-balance-quarterly" on disk (0 days old).
- Downloading ... 100.0%
- Extracting zip-file ... Done!
/Users/dongpinoh/anaconda3/lib/python3.11/site-packages/simfin/load.py:154: FutureWarning: The argument 'date_parser' is deprecated and will be removed in a future version. Please use 'date_format' instead, or read your data in as 'object' dtype and then call 'to_datetime'.
  df = pd.read_csv(path, sep=';', header=0,
- Loading from disk ... Done!
Dataset "us-cashflow-ttm" on disk (0 days old).
- Downloading ... 100.0%
- Extracting zip-file ... Done!
/Users/dongpinoh/anaconda3/lib/python3.11/site-packages/simfin/load.py:154: FutureWarning: The argument 'date_parser' is deprecated and will be removed in a future version. Please use 'date_format' instead, or read your data in as 'object' dtype and then call 'to_datetime'.
  df = pd.read_csv(path, sep=';', header=0,
- Loading from disk ... Done!
Dataset "us-cashflow-quarterly" on disk (0 days old).
- Downloading ... 100.0%
- Extracting zip-file ... Done!
/Users/dongpinoh/anaconda3/lib/python3.11/site-packages/simfin/load.py:154: FutureWarning: The argument 'date_parser' is deprecated and will be removed in a future version. Please use 'date_format' instead, or read your data in as 'object' dtype and then call 'to_datetime'.
  df = pd.read_csv(path, sep=';', header=0,
- Loading from disk ... Done!
Dataset "us-shareprices-daily" on disk (0 days old).
/Users/dongpinoh/anaconda3/lib/python3.11/site-packages/simfin/load.py:154: FutureWarning: The argument 'date_parser' is deprecated and will be removed in a future version. Please use 'date_format' instead, or read your data in as 'object' dtype and then call 'to_datetime'.
  df = pd.read_csv(path, sep=';', header=0,
- Loading from disk ... Done!
Cache-file 'growth_signals-2a38bb7d.pickle' not on disk.
- Running function growth_signals() ... Traceback (most recent call last):
  File "/Users/dongpinoh/pinsfund/test.py", line 30, in <module>
    df_growth_signals = hub.growth_signals(variant='daily')
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/dongpinoh/anaconda3/lib/python3.11/site-packages/simfin/hubs.py", line 582, in growth_signals
    df_result = growth_signals(df_income_ttm=df_income_ttm,
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/dongpinoh/anaconda3/lib/python3.11/site-packages/simfin/cache.py", line 266, in wrapper
    df_result = func(**kwargs)
                ^^^^^^^^^^^^^^
  File "/Users/dongpinoh/anaconda3/lib/python3.11/site-packages/simfin/signals.py", line 644, in growth_signals
    df_qrt = pd.concat([df_qrt1, df_qrt2, df_qrt3], axis=1)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/dongpinoh/anaconda3/lib/python3.11/site-packages/pandas/core/reshape/concat.py", line 395, in concat
    return op.get_result()
           ^^^^^^^^^^^^^^^
  File "/Users/dongpinoh/anaconda3/lib/python3.11/site-packages/pandas/core/reshape/concat.py", line 680, in get_result
    indexers[ax] = obj_labels.get_indexer(new_labels)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/dongpinoh/anaconda3/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3885, in get_indexer
    raise InvalidIndexError(self._requires_unique_msg)
pandas.errors.InvalidIndexError: Reindexing only valid with uniquely valued Index objects
thf24 commented 6 months ago

thanks for the report. We are currently doing some large changes to the data for the next update (will be online in the next days) so this might be related. Will update you once this is fixed.

thf24 commented 6 months ago

should work again now, sorry for the inconvenience.