OpenBBTerminal icon indicating copy to clipboard operation
OpenBBTerminal copied to clipboard

[Bug]stocks/ba/queries - google_view.py: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame.

Open deeleeramone opened this issue 2 years ago โ€ข 11 comments

stocks/ba/queries - SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame.

Does not break the terminal, but prints a warning message.

(๐Ÿฆ‹) /stocks/ba/ $ queries
/Users/danglewood/GitHub/OpenBBTerminal/openbb_terminal/common/behavioural_analysis/google_view.py:223: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  df_related_queries["value"] = df_related_queries["value"].apply(

 Top GME's related queries 
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ณโ”โ”โ”โ”โ”โ”โ”โ”“
โ”ƒ query           โ”ƒ value โ”ƒ
โ”กโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ”โ”ฉ
โ”‚ stock gme       โ”‚ 100%  โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ amc             โ”‚ 29%   โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ amc stock       โ”‚ 24%   โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ gme price       โ”‚ 23%   โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ gme stock price โ”‚ 14%   โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ gme share       โ”‚ 7%    โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ gme share price โ”‚ 6%    โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ reddit          โ”‚ 6%    โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ gme reddit      โ”‚ 6%    โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ bb              โ”‚ 5%    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

deeleeramone avatar May 23 '22 18:05 deeleeramone

myself and @deeleeramone no longer see this

jmaslek avatar May 27 '22 22:05 jmaslek

Reopening because I am now seeing this again.

Screen Shot 2022-08-19 at 8 28 18 AM

deeleeramone avatar Aug 19 '22 15:08 deeleeramone

I'm going to try to take this one. I'm also seeing it in stocks/options

boyestrous avatar Aug 19 '22 15:08 boyestrous

Learned some things yesterday:

  • for the stocks/options module - this message only occurs with certain expirations. TSLA, for example, only displays this error for 9/16/2022.
    • yesterday, this was exp 4, but today it's exp 3 and the error persists, so the warning isn't related to the index of the expiration
  • the stocks/ba module appears to show this warning every single time. I tested with BBBY, TSLA, GME, and AAPL

It occurred to me that this expiration is a "standard" expiration instead of a weekly one. So i checked other expirations and was unable to reproduce the warning for:

  • 10/21/2022 (standard expiration)
  • 11/18/2022 (standard expiration)
  • 12/16/2022 (standard expiration)

Needs more investigation. My current theory is that it may be related to the expiration being a "standard" within a month that also contains weekly ones. Not sure why that would be the case, but I'm going to have to keep testing.

boyestrous avatar Aug 20 '22 15:08 boyestrous

Interesting. Any thoughts here, @jmaslek?

deeleeramone avatar Aug 20 '22 22:08 deeleeramone

Does the command still work?

If it's just the warning that's usually just a pandas thing like the warning says

jmaslek avatar Aug 21 '22 02:08 jmaslek

It does work, but it would be nice to get rid of these messages.

image

deeleeramone avatar Aug 25 '22 15:08 deeleeramone

User report from this morning, where it doesn't work:

image

deeleeramone avatar Aug 25 '22 16:08 deeleeramone

I did some more research last night and found a couple of things:

for stocks/options

the warning occurs only when some of the options in the chain have implied volatility <= 0. Those rows are filtered out in yfinance_model, line 72: df_list = [x[x["impliedVolatility"] > 0] for x in df_list]

On line 80, when greeks are set, we're now modifying a slice of the original DataFrame. This only happens if there isn't enough activity for a certain option and the price remains constant, which is why this warning only appears intermittently.

There's no reason to keep the original df, so adding a .copy() statement will permanently handle the warning df_list = [x[x["impliedVolatility"] > 0].copy() for x in df_list]

for stocks/ba

I don't know why the warning is intermittent and it stopped appearing mid-testing last night (seems to be back this morning).

But, I actually found an unrelated issue that does break the functionality.

The --export flag no longer works for stocks/ba:

I can fix this pretty easily, but it's related to the same code that is likely causing the SettingWithCopyWarning. Should I make it a separate issue?

boyestrous avatar Aug 25 '22 16:08 boyestrous

Screen Shot 2022-08-25 at 12 29 46 PM

queries --export csv does break it in my installer package version.

Screen Shot 2022-08-25 at 12 30 55 PM

Do we need a new issue, or, just keep this one evolving because it is the same command it was raised for, @DidierRLopes?

deeleeramone avatar Aug 25 '22 19:08 deeleeramone

My two cents:

I can fix the export problem and both SettingWithCopyWarnings immediately with just a few tweaks. I am just working on updating the pytests because they don't appear to be properly checking whether the --export flag works correctly.

The other error (related to Google returning 429) is going to be a bit more involved. We'll have to look at the core _get_data() function and figure out how to make it return something that is acceptable to all of the other functions that call it. Right now, it raises an exception, but then it still returns the rest of the JSON response. Shouldn't be too tricky, but it's definitely a separate set of considerations, in my opinion.

boyestrous avatar Aug 26 '22 18:08 boyestrous