Skip to content

Commit

Permalink
[IMPROVE] Fix Docstring formatting/Fix missing, incomplete type hints (
Browse files Browse the repository at this point in the history
…#3412)

* Fixes

* Update stocks_helper.py

* update git-actions set-output to new format

* Update stocks_helper.py

* Update terminal_helper.py

* removed LineAnnotateDrawer from qa_view

* lint

* few changes

* updates

* sdk auto gen modules done

* Update stocks_helper.py

* updates to changed imports, and remove first sdk_modules

* Update generate_sdk.py

* Update generate_sdk.py

* pylint

* revert stocks_helper

* Update generate_sdk.py

* Update sdk.py

* Update generate_sdk.py

* full auto generation, added sdk.py/controllers creation

* missed enable forecasting

* added running black in subprocess after sdk files generation completes

* removed deleted sdk_arg_logger

* comment out tests

* property doc fix

* clean up

* Update generate_sdk.py

* make trailmap classes useable for doc generation

* Update generate_sdk.py

* added lineon to trailmap class for linking to func in markdown

* changed lineon to dict

* added full_path to trailmap for linking in docs

* updated portfolio

* feat: initial files

* feat: added meta head

* feat: added funcdef

* added func_def to trailmap attributes for markdown in docs, added missing type hints to covid functions

* feat: added view and merged with jaun

* Update generate_sdk.py

* Update generate_sdk.py

* Update generate_sdk.py

* Update generate_sdk.py

* init

* fix returns

* fix: random stuff

* fix: random

* fixed encoding issue on windows

* fix: generate tabs

* update

* Update generate_sdk_markdown.py

* Create .pydocstyle.ini

* added type hint classes for views

* fixes

* alt, ba

* alt-economy

* Update finviz_compare_model.py

* fixs

* Update substack_model.py

* Update generate_sdk.py

* last of my section

* porfolio

* po

* Update optimizer_model.py

* fixing more things

* few more

* keys done

* update

* fixes

* Update generate_sdk_markdown.py

* Update generate_sdk_markdown.py

* mypy forecast fix

* Update generate_sdk_markdown.py

* Update generate_sdk_markdown.py

* Update generate_sdk_markdown.py

* fixes

* forecast fixes

* one more fix

* Update coinbase_model.py

* Update generate_sdk_markdown.py

Co-authored-by: Colin Delahunty <[email protected]>
Co-authored-by: James Maslek <[email protected]>
Co-authored-by: jose-donato <[email protected]>
Co-authored-by: andrewkenreich <[email protected]>
  • Loading branch information
5 people authored Nov 15, 2022
1 parent 4495d4d commit 59d8b36
Show file tree
Hide file tree
Showing 228 changed files with 2,192 additions and 1,571 deletions.
4 changes: 4 additions & 0 deletions .pydocstyle.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[pydocstyle]
inherit = True
ignore = D202,D203,D205,D210,D212,D213,D214,D215,D400,D404,D405,D406,D407,D408,D409,D410,D411,D413,D415,D416,D417
match = .*\.py
40 changes: 32 additions & 8 deletions openbb_terminal/alternative/covid/covid_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

@log_start_end(log=logger)
def get_global_cases(country: str) -> pd.DataFrame:
"""Get historical cases for given country
"""Get historical cases for given country.
Parameters
----------
Expand All @@ -35,6 +35,21 @@ def get_global_cases(country: str) -> pd.DataFrame:
-------
pd.DataFrame
Dataframe of historical cases
Examples
--------
>>> df = get_global_cases("United States")
Dataframe of historical cases for United States
>>> df = get_global_cases("Portugal")
Dataframe of historical cases for Portugal
>>> df = get_global_cases("Spain")
Dataframe of historical cases for Spain
"""
cases = pd.read_csv(global_cases_time_series)
cases = cases.rename(columns={"Country/Region": "Country"})
Expand All @@ -53,7 +68,7 @@ def get_global_cases(country: str) -> pd.DataFrame:

@log_start_end(log=logger)
def get_global_deaths(country: str) -> pd.DataFrame:
"""Get historical deaths for given country
"""Get historical deaths for given country.
Parameters
----------
Expand Down Expand Up @@ -82,17 +97,22 @@ def get_global_deaths(country: str) -> pd.DataFrame:

@log_start_end(log=logger)
def get_covid_ov(
country,
country: str,
limit: int = 100,
) -> pd.DataFrame:
"""Get historical cases and deaths by country
"""Get historical cases and deaths by country.
Parameters
----------
country: str
Country to get data for
limit: int
Number of raw data to show
Returns
-------
pd.DataFrame
Dataframe of historical cases and deaths
"""
cases = get_global_cases(country)
deaths = get_global_deaths(country)
Expand All @@ -104,11 +124,11 @@ def get_covid_ov(

@log_start_end(log=logger)
def get_covid_stat(
country,
country: str,
stat: str = "cases",
limit: int = 10,
) -> pd.DataFrame:
"""Show historical cases and deaths by country
"""Show historical cases and deaths by country.
Parameters
----------
Expand All @@ -118,6 +138,11 @@ def get_covid_stat(
Statistic to get. Either "cases", "deaths" or "rates"
limit: int
Number of raw data to show
Returns
-------
pd.DataFrame
Dataframe of data for given country and statistic
"""
if stat == "cases":
data = get_global_cases(country)
Expand All @@ -141,7 +166,7 @@ def get_case_slopes(
threshold: int = 10000,
ascend: bool = False,
) -> pd.DataFrame:
"""Load cases and find slope over period
"""Load cases and find slope over period.
Parameters
----------
Expand All @@ -159,7 +184,6 @@ def get_case_slopes(
pd.DataFrame
Dataframe containing slopes
"""

# Ignore the pandas warning for setting a slace with a value
warnings.filterwarnings("ignore")
data = pd.read_csv(global_cases_time_series)
Expand Down
22 changes: 9 additions & 13 deletions openbb_terminal/alternative/covid/covid_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@

@log_start_end(log=logger)
def plot_covid_ov(
country,
country: str,
external_axes: Optional[List[plt.Axes]] = None,
) -> None:
"""Plot historical cases and deaths by country
"""Plots historical cases and deaths by country.
Parameters
----------
Expand All @@ -38,7 +38,6 @@ def plot_covid_ov(
external_axis: Optional[List[plt.Axes]]
List of external axes to include in plot
"""

cases = covid_model.get_global_cases(country) / 1_000
deaths = covid_model.get_global_deaths(country)
ov = pd.concat([cases, deaths], axis=1)
Expand Down Expand Up @@ -77,11 +76,11 @@ def plot_covid_ov(


def plot_covid_stat(
country,
country: str,
stat: str = "cases",
external_axes: Optional[List[plt.Axes]] = None,
) -> None:
"""Plot historical stat by country
"""Plots historical stat by country.
Parameters
----------
Expand All @@ -90,7 +89,6 @@ def plot_covid_stat(
external_axis: Optional[List[plt.Axes]]
List of external axes to include in plot
"""

# This plot has 1 axis
if external_axes is None:
_, ax = plt.subplots(figsize=plot_autoscale(), dpi=PLOT_DPI)
Expand Down Expand Up @@ -130,13 +128,13 @@ def plot_covid_stat(

@log_start_end(log=logger)
def display_covid_ov(
country,
country: str,
raw: bool = False,
limit: int = 10,
export: str = "",
plot: bool = True,
) -> None:
"""Show historical cases and deaths by country
"""Prints table showing historical cases and deaths by country.
Parameters
----------
Expand All @@ -151,7 +149,6 @@ def display_covid_ov(
plot: bool
Flag to display historical plot
"""

if plot:
plot_covid_ov(country)
if raw:
Expand All @@ -170,14 +167,14 @@ def display_covid_ov(

@log_start_end(log=logger)
def display_covid_stat(
country,
country: str,
stat: str = "cases",
raw: bool = False,
limit: int = 10,
export: str = "",
plot: bool = True,
) -> None:
"""Show historical cases and deaths by country
"""Prints table showing historical cases and deaths by country.
Parameters
----------
Expand All @@ -194,7 +191,6 @@ def display_covid_stat(
plot : bool
Flag to plot data
"""

if plot:
plot_covid_stat(country, stat)

Expand All @@ -219,7 +215,7 @@ def display_case_slopes(
ascend: bool = False,
export: str = "",
) -> None:
"""
"""Prints table showing countries with the highest case slopes.
Parameters
----------
Expand Down
50 changes: 29 additions & 21 deletions openbb_terminal/alternative/oss/github_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# pylint: disable=C0201,W1401

import logging
from typing import Any, Dict
from typing import Any, Dict, Optional
import math
from datetime import datetime
import requests
Expand All @@ -18,18 +18,20 @@


@check_api_key(["API_GITHUB_KEY"])
def get_github_data(url: str, **kwargs):
"""Get repository stats
def get_github_data(url: str, **kwargs) -> Optional[Dict[str, Any]]:
"""Get repository stats.
Parameters
----------
url: str
github api endpoint
params: dict
params to pass to api endpoint
Returns
-------
dict with data
Dict[str, Any]
Dictionary with data
"""
res = requests.get(
url,
Expand All @@ -54,19 +56,21 @@ def get_github_data(url: str, **kwargs):
def search_repos(
sortby: str = "stars", page: int = 1, categories: str = ""
) -> pd.DataFrame:
"""Get repos sorted by stars or forks. Can be filtered by categories
"""Get repos sorted by stars or forks. Can be filtered by categories.
Parameters
----------
sortby : str
Sort repos by {stars, forks}
Sort repos by {stars, forks}
categories : str
Check for repo categories. If more than one separate with a comma: e.g., finance,investment. Default: None
Check for repo categories. If more than one separate with a comma: e.g., finance,investment. Default: None
page : int
Page number to get repos
Page number to get repos
Returns
-------
pd.DataFrame with list of repos
pd.DataFrame
Dataframe with repos
"""
params: Dict[str, Any] = {"page": page}
if categories:
Expand All @@ -81,17 +85,18 @@ def search_repos(


@log_start_end(log=logger)
def get_stars_history(repo: str):
"""Get repository star history
def get_stars_history(repo: str) -> pd.DataFrame:
"""Get repository star history.
Parameters
----------
repo : str
Repo to search for Format: org/repo, e.g., openbb-finance/openbbterminal
Repo to search for Format: org/repo, e.g., openbb-finance/openbbterminal
Returns
-------
pd.DataFrame - Columns: Date, Stars
pd.DataFrame
Dataframe with star history - Columns: Date, Stars
"""
data = get_github_data(f"https://api.github.com/repos/{repo}")
if data and "stargazers_count" in data:
Expand Down Expand Up @@ -128,19 +133,21 @@ def get_stars_history(repo: str):

@log_start_end(log=logger)
def get_top_repos(sortby: str, limit: int = 50, categories: str = "") -> pd.DataFrame:
"""Get repos sorted by stars or forks. Can be filtered by categories
"""Get repos sorted by stars or forks. Can be filtered by categories.
Parameters
----------
sortby : str
Sort repos by {stars, forks}
Sort repos by {stars, forks}
categories : str
Check for repo categories. If more than one separate with a comma: e.g., finance,investment. Default: None
Check for repo categories. If more than one separate with a comma: e.g., finance,investment. Default: None
limit : int
Number of repos to search for
Number of repos to search for
Returns
-------
pd.DataFrame with list of repos
pd.DataFrame
Dataframe with repos
"""
initial_top = limit
df = pd.DataFrame(
Expand Down Expand Up @@ -170,16 +177,17 @@ def get_top_repos(sortby: str, limit: int = 50, categories: str = "") -> pd.Data

@log_start_end(log=logger)
def get_repo_summary(repo: str) -> pd.DataFrame:
"""Get repository summary
"""Get repository summary.
Parameters
----------
repo : str
Repo to search for Format: org/repo, e.g., openbb-finance/openbbterminal
Repo to search for Format: org/repo, e.g., openbb-finance/openbbterminal
Returns
-------
pd.DataFrame - Columns: Metric, Value
pd.DataFrame
Dataframe with repo summary - Columns: Metric, Value
"""
data = get_github_data(f"https://api.github.com/repos/{repo}")
if not data:
Expand Down
14 changes: 7 additions & 7 deletions openbb_terminal/alternative/oss/github_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@
def display_star_history(
repo: str, export: str = "", external_axes: Optional[List[plt.Axes]] = None
) -> None:
"""Display repo summary [Source: https://api.github.com]
"""Plots repo summary [Source: https://api.github.com].
Parameters
----------
repo : str
Repository to display star history. Format: org/repo, e.g., openbb-finance/openbbterminal
Repository to display star history. Format: org/repo, e.g., openbb-finance/openbbterminal
export : str
Export dataframe data to csv,json,xlsx file
Export dataframe data to csv,json,xlsx file
external_axes : Optional[List[plt.Axes]], optional
External axes (1 axis is expected in the list), by default None
External axes (1 axis is expected in the list), by default None
"""
df = github_model.get_stars_history(repo)
if not df.empty:
Expand Down Expand Up @@ -69,7 +69,7 @@ def display_top_repos(
export: str = "",
external_axes: Optional[List[plt.Axes]] = None,
) -> None:
"""Display repo summary [Source: https://api.github.com]
"""Plots repo summary [Source: https://api.github.com].
Parameters
----------
Expand Down Expand Up @@ -121,12 +121,12 @@ def display_top_repos(

@log_start_end(log=logger)
def display_repo_summary(repo: str, export: str = "") -> None:
"""Display repo summary [Source: https://api.github.com]
"""Prints table showing repo summary [Source: https://api.github.com].
Parameters
----------
repo : str
Repository to display summary. Format: org/repo, e.g., openbb-finance/openbbterminal
Repository to display summary. Format: org/repo, e.g., openbb-finance/openbbterminal
export : str
Export dataframe data to csv,json,xlsx file
"""
Expand Down
Loading

0 comments on commit 59d8b36

Please sign in to comment.