Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…BBTerminal into hotfix/#3442
  • Loading branch information
tehcoderer committed Mar 17, 2023
2 parents 3ea143f + 7aa9e39 commit c53c690
Show file tree
Hide file tree
Showing 15 changed files with 7,318 additions and 2,938 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
restore-keys: ${{ runner.os }}-linting-${{ hashFiles('**/poetry.lock') }}

- run: |
pip install bandit black codespell mypy==1.0.0 pylint==2.15.2 ruff==0.0.247
pip install bandit black codespell mypy==1.1.1 pylint==2.17.0 ruff==0.0.256
pip install types-pytz types-requests types-termcolor types-tabulate types-PyYAML types-python-dateutil types-setuptools types-six
- run: bandit -x ./tests -r . || true
- run: black --diff --check .
Expand Down
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ repos:
hooks:
- id: black
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.0.247'
rev: 'v0.0.256'
hooks:
- id: ruff
- repo: https://github.com/codespell-project/codespell
rev: v2.2.2
rev: v2.2.4
hooks:
- id: codespell
entry: codespell
Expand Down Expand Up @@ -47,7 +47,7 @@ repos:
hooks:
- id: pylint
name: pylint
entry: pylint openbb_terminal terminal.py tests -j 4
entry: pylint openbb_terminal terminal.py tests -j 0
language: system
types: [python]
- repo: https://github.com/Yelp/detect-secrets
Expand Down
5 changes: 3 additions & 2 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ confidence=
# disable=import-error,print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call
# disable=too-many-instance-attributes,len-as-condition,too-few-public-methods,anomalous-backslash-in-string,no-else-return,simplifiable-if-statement,too-many-arguments,duplicate-code,no-name-in-module,no-member,print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,missing-docstring,invalid-name,bad-whitespace,consider-using-enumerate,unexpected-keyword-arg

disable=useless-return,missing-docstring,invalid-name,import-error,broad-except,unnecessary-lambda,missing-timeout,duplicate-code,consider-using-generator,unbalanced-tuple-unpacking,use-list-literal,no-name-in-module,use-sequence-for-iteration,use-dict-literal,unspecified-encoding,unsubscriptable-object
disable=useless-return,missing-docstring,invalid-name,import-error,broad-except,unnecessary-lambda,missing-timeout,duplicate-code,consider-using-generator,unbalanced-tuple-unpacking,use-list-literal,no-name-in-module,use-sequence-for-iteration,use-dict-literal,unspecified-encoding,unsubscriptable-object,broad-exception-raised

# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
Expand Down Expand Up @@ -395,4 +395,5 @@ min-public-methods=1

# Exceptions that will emit a warning when being caught. Defaults to
# "Exception"
overgeneral-exceptions=Exception
overgeneral-exceptions=builtins.BaseException,
builtins.Exception
16 changes: 8 additions & 8 deletions openbb_terminal/alternative/realestate/landRegistry_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,19 +138,19 @@ def get_towns_sold_prices(
prefix skos: <http://www.w3.org/2004/02/skos/core#>
prefix lrcommon: <http://landregistry.data.gov.uk/def/common/>
SELECT ?paon ?saon ?street ?county ?postcode ?amount ?date ?category
SELECT ?paon ?saon ?street ?county ?postcode ?amount ?date ?category
WHERE
{{
VALUES ?town {{"{town}"^^xsd:string}}
?addr lrcommon:town ?town ;
lrcommon:postcode ?postcode.
?transx lrppi:propertyAddress ?addr ;
lrppi:pricePaid ?amount ;
lrppi:transactionDate ?date ;
lrppi:transactionCategory/skos:prefLabel ?category.
FILTER (
?date > "{start_date}"^^xsd:date &&
?date < "{end_date}"^^xsd:date
Expand Down Expand Up @@ -220,13 +220,13 @@ def get_region_stats(
prefix skos: <http://www.w3.org/2004/02/skos/core#>
prefix lrcommon: <http://landregistry.data.gov.uk/def/common/>
SELECT ?month ?avgPrice ?avgPriceCash ?totalSalesVolume ?avgPriceExistingProperty
?avgPriceFirstTimeBuyer
?avgPriceDetached ?hpi ?detachedhpi ?newbuildhpi
SELECT ?month ?avgPrice ?avgPriceCash ?totalSalesVolume ?avgPriceExistingProperty
?avgPriceFirstTimeBuyer
?avgPriceDetached ?hpi ?detachedhpi ?newbuildhpi
{{
values ?refRegion {{<http://landregistry.data.gov.uk/id/region/{region}>}}
?region ukhpi:refPeriodStart ?month ;
ukhpi:housePriceIndex ?hpi ;
ukhpi:housePriceIndex ?hpi ;
ukhpi:refRegion ?refRegion ;
ukhpi:averagePrice ?avgPrice ;
ukhpi:averagePriceCash ?avgPriceCash ;
Expand All @@ -242,7 +242,7 @@ def get_region_stats(
?month > "{start_date}"^^xsd:date &&
?month < "{end_date}"^^xsd:date
)
OPTIONAL {{?region ukhpi:housePriceIndexDetached ?detachedhpi}}
OPTIONAL {{?region ukhpi:housePriceIndexNewBuild ?newbuildhpi }}
OPTIONAL {{?region ukhpi:averagePrice ?averagePrice }}
Expand Down
2 changes: 1 addition & 1 deletion openbb_terminal/core/plots/plotly_helper.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Chart and style helpers for Plotly."""
# pylint: disable=C0302,R0902
# pylint: disable=C0302,R0902,W3301
import json
import os
import textwrap
Expand Down
12 changes: 6 additions & 6 deletions openbb_terminal/core/session/current_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

__profile = ProfileModel()
__local_user = UserModel( # type: ignore
credentials=__credentials,
preferences=__preferences,
credentials=__credentials, # type: ignore
preferences=__preferences, # type: ignore
profile=__profile,
)
__current_user = __local_user
Expand Down Expand Up @@ -101,8 +101,8 @@ def set_preference(
Preference value
"""
current_user = get_current_user()
updated_preferences = dataclasses.replace(current_user.preferences, **{name: value})
updated_user = dataclasses.replace(current_user, preferences=updated_preferences)
updated_preferences = dataclasses.replace(current_user.preferences, **{name: value}) # type: ignore
updated_user = dataclasses.replace(current_user, preferences=updated_preferences) # type: ignore
set_current_user(updated_user)


Expand All @@ -117,6 +117,6 @@ def set_credential(name: str, value: str):
Credential value
"""
current_user = get_current_user()
updated_credentials = dataclasses.replace(current_user.credentials, **{name: value})
updated_user = dataclasses.replace(current_user, credentials=updated_credentials)
updated_credentials = dataclasses.replace(current_user.credentials, **{name: value}) # type: ignore
updated_user = dataclasses.replace(current_user, credentials=updated_credentials) # type: ignore
set_current_user(updated_user)
11 changes: 7 additions & 4 deletions openbb_terminal/forex/oanda/oanda_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@
current_user = get_current_user()

if current_user.credentials.OANDA_ACCOUNT_TYPE != "REPLACE_ME":
client = API(
access_token=current_user.credentials.OANDA_TOKEN,
environment=current_user.credentials.OANDA_ACCOUNT_TYPE,
)
try:
client = API(
access_token=current_user.credentials.OANDA_TOKEN,
environment=current_user.credentials.OANDA_ACCOUNT_TYPE,
)
except KeyError:
client = None
else:
client = None
account = current_user.credentials.OANDA_ACCOUNT
Expand Down
1 change: 1 addition & 0 deletions openbb_terminal/keys_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def __str__(self):
return self.value

def colorize(self):
c = ""
if self.name == self.DEFINED_TEST_FAILED.name:
c = "red"
elif self.name == self.NOT_DEFINED.name:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import os
import textwrap
from datetime import datetime, timedelta
from functools import partial
from typing import Optional, Union

import pandas as pd
from pandas.core.frame import DataFrame

from openbb_terminal import OpenBBFigure, theme
Expand All @@ -17,7 +19,10 @@
print_rich_table,
)
from openbb_terminal.rich_config import console
from openbb_terminal.stocks.fundamental_analysis import business_insider_model
from openbb_terminal.stocks.fundamental_analysis import (
business_insider_model,
yahoo_finance_model,
)
from openbb_terminal.stocks.stocks_helper import load

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -61,6 +66,7 @@ def display_management(symbol: str, export: str = "", sheet_name: Optional[str]
logger.error("Data not available")


# pylint: disable=R0913
@log_start_end(log=logger)
def price_target_from_analysts(
symbol: str,
Expand All @@ -71,6 +77,7 @@ def price_target_from_analysts(
export: str = "",
sheet_name: Optional[str] = None,
external_axes: bool = False,
adjust_for_splits: bool = True,
) -> Union[OpenBBFigure, None]:
"""Display analysts' price targets for a given stock. [Source: Business Insider]
Expand All @@ -92,13 +99,22 @@ def price_target_from_analysts(
Export dataframe data to csv,json,xlsx file
external_axes: bool, optional
Whether to return the figure object or not, by default False
adjust_for_splits: bool
Whether to adjust analyst price targets for stock splits, by default True
Examples
--------
>>> from openbb_terminal.sdk import openbb
>>> openbb.stocks.fa.pt_chart(symbol="AAPL")
"""

def adjust_splits(row, splits: pd.DataFrame):
original_value = row["Price Target"]
for index, sub_row in splits.iterrows():
if row.name < index:
original_value = original_value / sub_row["Stock Splits"]
return round(original_value, 2)

if start_date is None:
start_date = (datetime.now() - timedelta(days=1100)).strftime("%Y-%m-%d")

Expand All @@ -108,6 +124,11 @@ def price_target_from_analysts(
df_analyst_data = business_insider_model.get_price_target_from_analysts(symbol)
if df_analyst_data.empty:
return console.print("[red]Could not get data for ticker.[/red]\n")
if adjust_for_splits:
df_splits = yahoo_finance_model.get_splits(symbol)
df_splits.index = df_splits.index.tz_convert(None)
adjusted_splits = partial(adjust_splits, splits=df_splits)
df_analyst_data["Price Target"] = df_analyst_data.apply(adjusted_splits, axis=1)

fig = OpenBBFigure(yaxis_title="Share Price").set_title(
f"{symbol} (Time Series) and Price Target"
Expand Down
54 changes: 27 additions & 27 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c53c690

Please sign in to comment.