Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config #2216

Open
wants to merge 23 commits into
base: dev
Choose a base branch
from
Open

Config #2216

wants to merge 23 commits into from

Conversation

R5dan
Copy link
Contributor

@R5dan R5dan commented Jan 10, 2025

Supersedes #2209 with better implementation.

Changes:

  • Deprecates all proxy, session and timeout in functions
  • Adds yf.set_config
  • Allows setting:
    • proxy
    • session
    • timout
    • url
    • language
    • region
  • Adds deprecator for future use
  • Adds docs for use of yf.set_config

@R5dan R5dan mentioned this pull request Jan 10, 2025
@R5dan
Copy link
Contributor Author

R5dan commented Jan 11, 2025

@ValueRaider what do you think? Happy to move yf.set_config if you can think of somewhere. I have deprecated all of the session, proxy and timeout (thats why its adding code not removing it but that can all go away in a few versions time)

@R5dan
Copy link
Contributor Author

R5dan commented Jan 19, 2025

@ValueRaider What do you think?

@ValueRaider
Copy link
Collaborator

I haven't had time to try and review yet.

@ValueRaider
Copy link
Collaborator

ValueRaider commented Jan 25, 2025

yf.set_config is fine.

Remove stuff to simplify deprecated:

  • removed_in

  • is **message_params actually used anywhere? If not, remove it.

  • remove since as well, how can developer always know which version their PR will end up in?

User should not be informed on internal deprecations that aren't their fault. Best solution probably is: if proxy argument not None, pass it to YfData, and leave a comment to remove with deprecations.

> dat.balance_sheet
yfinance/scrapers/fundamentals.py:99: DeprecationWarning: Parameter 'proxy' of Financials.get_financials_time_series is deprecated

Set new on everything, so user is told the new function or argument.

What happens if user changes session with set_config after YfData singleton already created?

Reduce timeout default to 10. I know some places did 30, but others did 10.

@R5dan
Copy link
Contributor Author

R5dan commented Jan 26, 2025

  • remove since as well, how can developer always know which version their PR will end up in?

Unless it is near the next release cycle, it is normally pretty obvious, plus it can always be changed - like I'm going to have to do now. I think this should stay as (1) more information never hurt - even if just for devs and (2) it lets the user know when it was deprecated, so if they really wanted to or needed to could revert back to that until they change it. However i will remove it if needed.

  • removed_in

I think this should probably stay as it tells them exactly when to change by.
With this PR I would also like to add a 2 or 3 release gap between all deprecations and removals as I believe earnings in fundamentals has been deprecated since 0.2.41

  • is **message_params actually used anywhere? If not, remove it.

I don't believe it is however think it should stay for future use.

User should not be informed on internal deprecations that aren't their fault

Yes, I agree. I marked the "getters" with deprecate as they weren't the common "private attributes"

dat.balance_sheet
yfinance/scrapers/fundamentals.py:99: DeprecationWarning: Parameter 'proxy' of Financials.get_financials_time_series is deprecated

That shouldn't raise a Deprecation Warning as it doesn't set proxy. Will fix.

Set new on everything, so user is told the new function or argument.

Not possible for proxy session or timeout as they are simply removed. I don't believe I am deprecating anything that have replacements.

What happens if user changes session with set_config after YfData singleton already created?

In my initial testing of it, it seemed to work. However it doesn't seem to set it if its called after. Will have to fix. Any ideas how to?

I will change the default of timeout

@ValueRaider
Copy link
Collaborator

OK keep since. But removed_in is still a problem for us developers - the gap is determined by time more than number of releases and we don't have a regular release schedule.

**message_params should stay for future use

Without a current use case it isn't immediately obvious what it does. I figured it out and saw a bug, it's broken. Also the variable name could be more specific.

Not possible for proxy session or timeout as they are simply removed. I don't believe I am deprecating anything that have replacements.

You need to inform users of the replacement in that deprecation message. That's my point.

Move set_config to the YfData class like a normal setter function.

Run the unit tests to check for bugs. You might need to rebase to latest dev (not merge) to pull in fixes.

@R5dan
Copy link
Contributor Author

R5dan commented Jan 27, 2025

@ValueRaider I have made changes to the branch having already rebased and it now wont let me push due to:

To https://github.com/R5dan/yfinance-package.git
 ! [rejected]        ConfigV2 -> ConfigV2 (non-fast-forward)
error: failed to push some refs to 'https://github.com/R5dan/yfinance-package.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. If you want to integrate the remote changes,
hint: use 'git pull' before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

But there isn't any upstream changes etc. Any ideas?

@ValueRaider
Copy link
Collaborator

Immediately after the rebase (done on your local system), do a force push to your fork #1084

@R5dan
Copy link
Contributor Author

R5dan commented Jan 28, 2025

@ValueRaider How is this?

@ValueRaider ValueRaider mentioned this pull request Feb 1, 2025
@ValueRaider
Copy link
Collaborator

How are you testing this?

@R5dan
Copy link
Contributor Author

R5dan commented Feb 2, 2025

@ValueRaider sorry for the late reply. I updated the tests and have been running them

@ValueRaider
Copy link
Collaborator

ValueRaider commented Feb 2, 2025

Do you use this branch as your daily driver?

Bug:

import yfinance as yf
yf.set_config()

NameError: name 'requests' is not defined

Then with yf.Ticker('NVDA').balance_sheet, user gets a wall of warning messages that aren't directly related to their code:

uilt doc:
..warning::
    The following parameters are deprecated
    *proxy*      `proxy` is deprecated. Please set it using `yf.set_config`
    *session*    `session` is deprecated. Please set it using `yf.set_config`
Built doc:
..warning::
    The following parameters are deprecated
    *proxy*    `proxy` is deprecated. Please set it using `yf.set_config`
Built doc:
..warning::
    The following parameters are deprecated
    *proxy*    `proxy` is deprecated. Please set it using `yf.set_config`
Built doc:
..warning::
    The following parameters are deprecated
    *proxy*    `proxy` is deprecated. Please set it using `yf.set_config`
Built doc:
..warning::
    The following parameters are deprecated
    *proxy*    `proxy` is deprecated. Please set it using `yf.set_config`
Built doc:
..warning::
    The following parameters are deprecated
    *proxy*    `proxy` is deprecated. Please set it using `yf.set_config`

        :Parameters:
            as_dict: bool
                Return table as Python dict
                Default is False
            pretty: bool
                Format row names nicely for readability
                Default is False
            freq: str
                "yearly" or "quarterly"
                Default is "yearly"
            proxy: str
                Optional. Proxy server URL scheme
                Default is None
        
Built doc:
..warning::
    The following parameters are deprecated
    *proxy*    `proxy` is deprecated. Please set it using `yf.set_config`
bs: <class 'pandas.core.frame.DataFrame'>

@R5dan
Copy link
Contributor Author

R5dan commented Feb 2, 2025

Do you use this branch as your daily driver?

No

Bug:

import yfinance as yf
yf.set_config()

NameError: name 'requests' is not defined

Fixed

Then with yf.Ticker('NVDA').balance_sheet, user gets a wall of warning messages that aren't directly related to their code:

They were debug prints I forgot to remove. Removed now.

@dhruvan2006
Copy link
Contributor

Do you use this branch as your daily driver?

No

Would highly suggest you to use and test your own branch.

Bug:

import yfinance as yf

yf.Ticker("AAPL").history()
C:\Users\dhruv\yfinance\yfinance\base.py:86: DeprecationWarning: `proxy` is deprecated. Please set it using `yf.set_config`
Deprecated since version 0.2.53
`timeout` is deprecated. Please set it using `yf.set_config`
Deprecated since version 0.2.53
  self._price_history = PriceHistory(self._data, self.ticker, self._get_ticker_tz(self.proxy, timeout=10))
$AAPL: possibly delisted; no price data found  (period=1mo)

Empty DataFrame
Columns: [Open, High, Low, Close, Adj Close, Volume]
Index: []

@R5dan
Copy link
Contributor Author

R5dan commented Feb 6, 2025

Would highly suggest you to use and test your own branch.

I do test them, just not thoroughly enough obviously

Bug:

import yfinance as yf

yf.Ticker("AAPL").history()
C:\Users\dhruv\yfinance\yfinance\base.py:86: DeprecationWarning: `proxy` is deprecated. Please set it using `yf.set_config`
Deprecated since version 0.2.53
`timeout` is deprecated. Please set it using `yf.set_config`
Deprecated since version 0.2.53
  self._price_history = PriceHistory(self._data, self.ticker, self._get_ticker_tz(self.proxy, timeout=10))
$AAPL: possibly delisted; no price data found  (period=1mo)

Empty DataFrame
Columns: [Open, High, Low, Close, Adj Close, Volume]
Index: []

Weird, it seems like history is getting called twice - or more the deprecated wrapper is getting called twice but I can't find from where. One of them is being called with: {'self': yfinance.Ticker object <AAPL>, 'proxy': None, 'timeout': 10} which causes timeout and proxy to be flagged and another with what it should be {'self': <yfinance.scrapers.history.PriceHistory object at 0x00000254A69AACF0>}

@dhruvan2006
Copy link
Contributor

Weird, it seems like history is getting called twice

I think you need to search the whole codebase and remove every occurrence of passing proxy, session, etc. down to YfData

@R5dan
Copy link
Contributor Author

R5dan commented Feb 6, 2025

I think you need to search the whole codebase and remove every occurrence of passing proxy, session, etc. down to YfData

I did initially, but @ValueRaider told me to deprecate them instead.

@ValueRaider
Copy link
Collaborator

ValueRaider commented Feb 6, 2025

or more the deprecated wrapper is getting called twice but I can't find from where

Would removing the deprecated wrapper from scrapers/* help? Only need them on official API. Any users directly calling internal functions can cope with breaking changes.

I think you need to search the whole codebase and remove every occurrence of passing proxy, session, etc. down to YfData

My philosophy is similar to Pandas - warn users of breaking changes early, gives them time to adjust their codes. No one wants their algo-trading to suddenly break.

@R5dan
Copy link
Contributor Author

R5dan commented Feb 6, 2025

I think you need to search the whole codebase and remove every occurrence of passing proxy, session, etc. down to YfData

My philosophy is similar to Pandas - warn users of breaking changes early, gives them time to adjust their codes. No one wants their algo-trading to suddenly break.

Yes, I after you mentioned it, I agree with this. You should not just remove anything

or more the deprecated wrapper is getting called twice but I can't find from where

Would removing the deprecated wrapper from scrapers/* help? Only need them on official API. Any users directly calling internal functions can cope with breaking changes.

Problem is, functions like history are just run the function with args and kwargs. This means all the defaults and parameters are on the scrapers/* functions, which deprecated requires.

@ValueRaider
Copy link
Collaborator

functions like history are just run the function with args and kwargs

This was just me being lazy back when I moved the fetch logic into scrapers/history.py. It also breaks the auto-docs. Can you copy over the actual arguments?

@R5dan
Copy link
Contributor Author

R5dan commented Feb 9, 2025

This was just me being lazy back when I moved the fetch logic into scrapers/history.py. It also breaks the auto-docs. Can you copy over the actual arguments?

I thought I had mentioned this before and you said no. Anyway added now.

Also I fixed the bug

Any ideas on how to implement the custom url? Will probably just have it as a class attribute to YfData

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants