Error when switching between pages in app

The app is set to private for my team so I can’t show the whole thing :frowning: sorry. But I’ll provide best info I can.

I’m using Python3.11 but I also tried with Python3.8 and Python3.10 with the same output.

streamlit==1.29.0
pandas==2.1.4
matplotlib==3.8.2
numpy==1.26.2
requests==2.31.0
altair==5.2.0

I have a Streamlit app where there are 2 pages: page 1, stock info is shown and page 2, where news is shown for the stock. Everything is working fine until I use the “news” page, then when i run the other pages of the app, I get the following errors:

  • I’ve tried resolving the error messages themselves but then the same error will show for the modules I’ve downloaded so I don’t think my code is the reason.
  • I’ve tried reinstalling the Python environment several times and with every Python version i tried
  • I’ve tried clearing the cache on every iteration with env/bin/streamlit cache clear

The weirdest thing is that the page will work as intended until i visit and run the news page. Then returning to the other pages yields the errors. This makes me believe the syntax is not the cause and that the errors are not accurate.

For a stock symbol which i used in the News page

TypeError: isinstance() arg 2 must be a type, a tuple of types, or a union

File "/workspaces/xxx/env/lib/python3.11/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 534, in _run_script
    exec(code, module.__dict__)
File "/workspaces/xxx/pages/2_📈_Stock_symbol.py", line 61, in <module>
    is_auth(main, url_args)
File "/workspaces/xxx/passphrase/utils.py", line 18, in is_auth
    return main()
           ^^^^^^
File "/workspaces/xxx/pages/2_📈_Stock_symbol.py", line 46, in main
    show_historical_chart(symbol_value.upper(), days_ago_input(selection_days))
File "/workspaces/xxx/deps/charts/charts.py", line 88, in show_historical_chart
    st.altair_chart(
File "/workspaces/xxx/env/lib/python3.11/site-packages/streamlit/runtime/metrics_util.py", line 396, in wrapped_func
    result = non_optional_func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspaces/xxx/env/lib/python3.11/site-packages/streamlit/elements/arrow_altair.py", line 801, in altair_chart
    marshall(
File "/workspaces/xxx/env/lib/python3.11/site-packages/streamlit/elements/arrow_altair.py", line 1531, in marshall
    chart_dict = altair_chart.to_dict()
                 ^^^^^^^^^^^^^^^^^^^^^^
File "/workspaces/xxx/env/lib/python3.11/site-packages/altair/vegalite/v5/api.py", line 961, in to_dict
    vegalite_spec = super(TopLevelMixin, copy).to_dict(  # type: ignore[misc]
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspaces/xxx/env/lib/python3.11/site-packages/altair/utils/schemapi.py", line 961, in to_dict
    result = _todict(
             ^^^^^^^^
File "/workspaces/xxx/env/lib/python3.11/site-packages/altair/utils/schemapi.py", line 477, in _todict
    return {k: _todict(v, context) for k, v in obj.items() if v is not Undefined}
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspaces/xxx/env/lib/python3.11/site-packages/altair/utils/schemapi.py", line 477, in <dictcomp>
    return {k: _todict(v, context) for k, v in obj.items() if v is not Undefined}
               ^^^^^^^^^^^^^^^^^^^
File "/workspaces/xxx/env/lib/python3.11/site-packages/altair/utils/schemapi.py", line 475, in _todict
    return [_todict(v, context) for v in obj]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspaces/xxx/env/lib/python3.11/site-packages/altair/utils/schemapi.py", line 475, in <listcomp>
    return [_todict(v, context) for v in obj]
            ^^^^^^^^^^^^^^^^^^^
File "/workspaces/xxx/env/lib/python3.11/site-packages/altair/utils/schemapi.py", line 473, in _todict
    return obj.to_dict(validate=False, context=context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspaces/xxx/env/lib/python3.11/site-packages/altair/vegalite/v5/api.py", line 950, in to_dict
    copy.data = _prepare_data(original_data, context)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspaces/xxx/env/lib/python3.11/site-packages/altair/vegalite/v5/api.py", line 110, in _prepare_data
    elif isinstance(data, pd.DataFrame) or hasattr(data, "__geo_interface__"):
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

For new stock symbols

TypeError: 'DataFrame' object is not callable

File "/workspaces/xxx/env/lib/python3.11/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 534, in _run_script
    exec(code, module.__dict__)
File "/workspaces/xxx/pages/2_📈_Stock_symbol.py", line 61, in <module>
    is_auth(main, url_args)
File "/workspaces/xxx/passphrase/utils.py", line 18, in is_auth
    return main()
           ^^^^^^
File "/workspaces/xxx/pages/2_📈_Stock_symbol.py", line 46, in main
    show_historical_chart(symbol_value.upper(), days_ago_input(selection_days))
File "/workspaces/xxx/deps/charts/charts.py", line 49, in show_historical_chart
    historic_prices_df: pd.DataFrame = get_historic_prices(symbol, days_ago)
                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspaces/xxx/env/lib/python3.11/site-packages/streamlit/runtime/caching/cache_utils.py", line 212, in wrapper
    return cached_func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspaces/xxx/env/lib/python3.11/site-packages/streamlit/runtime/caching/cache_utils.py", line 241, in __call__
    return self._get_or_create_cached_value(args, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspaces/XXX/env/lib/python3.11/site-packages/streamlit/runtime/caching/cache_utils.py", line 267, in _get_or_create_cached_value
    return self._handle_cache_miss(cache, value_key, func_args, func_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspaces/xxx/env/lib/python3.11/site-packages/streamlit/runtime/caching/cache_utils.py", line 321, in _handle_cache_miss
    computed_value = self._info.func(*func_args, **func_kwargs)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspaces/xxx/deps/yahoo.py", line 106, in get_historic_prices
    history = df.history(period=f"{days_ago}d")
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspaces/xxx/env/lib/python3.11/site-packages/yfinance/utils.py", line 108, in wrapper
    result = func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^
File "/workspaces/xxx/env/lib/python3.11/site-packages/yfinance/base.py", line 283, in history
    shared._DFS[self.ticker] = utils.empty_df()
                               ^^^^^^^^^^^^^^^^
File "/workspaces/xxx/env/lib/python3.11/site-packages/yfinance/utils.py", line 228, in empty_df
    empty = _pd.DataFrame(index=index, data={
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

requirements.txt

altair==5.2.0
appdirs==1.4.4
astroid==3.0.2
attrs==23.1.0
beautifulsoup4==4.12.2
blinker==1.7.0
cachetools==5.3.2
certifi==2023.11.17
charset-normalizer==3.3.2
click==8.1.7
contourpy==1.2.0
cycler==0.12.1
dill==0.3.7
fonttools==4.46.0
frozendict==2.3.10
gitdb==4.0.11
GitPython==3.1.40
google-api-core==2.15.0
google-auth==2.25.2
google-cloud-secret-manager==2.17.0
googleapis-common-protos==1.62.0
grpc-google-iam-v1==0.13.0
grpcio==1.60.0
grpcio-status==1.60.0
html5lib==1.1
idna==3.6
importlib-metadata==6.11.0
importlib-resources==6.1.1
isort==5.13.2
Jinja2==3.1.2
jsonschema==4.20.0
jsonschema-specifications==2023.11.2
kiwisolver==1.4.5
lazy-object-proxy==1.10.0
lxml==4.9.3
markdown-it-py==3.0.0
MarkupSafe==2.1.3
matplotlib==3.8.2
mccabe==0.7.0
mdurl==0.1.2
multitasking==0.0.11
numpy==1.26.2
packaging==23.2
pandas==2.1.4
peewee==3.17.0
Pillow==10.1.0
platformdirs==4.1.0
proto-plus==1.23.0
protobuf==4.25.1
pyarrow==14.0.1
pyasn1==0.5.1
pyasn1-modules==0.3.0
pydeck==0.8.0
Pygments==2.17.2
pylint==3.0.3
Pympler==1.0.1
pyparsing==3.1.1
python-dateutil==2.8.2
pytz==2023.3.post1
pytz-deprecation-shim==0.1.0.post0
referencing==0.32.0
requests==2.31.0
rich==13.7.0
rpds-py==0.15.2
rsa==4.9
six==1.16.0
smmap==5.0.1
soupsieve==2.5
streamlit==1.29.0
tenacity==8.2.3
toml==0.10.2
tomli==2.0.1
tomlkit==0.12.3
toolz==0.12.0
tornado==6.4
typing_extensions==4.9.0
tzdata==2023.3
tzlocal==5.2
urllib3==2.1.0
validators==0.22.0
watchdog==3.0.0
webencodings==0.5.1
wrapt==1.16.0
yfinance==0.2.33
zipp==3.17.0