mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-30 14:02:06 +00:00
Add more docstrings
Co-authored-by: @the-praxs
This commit is contained in:
@@ -5,26 +5,24 @@ import re
|
||||
from typing import Callable, Dict, List, Optional, Type, Union
|
||||
|
||||
import requests
|
||||
|
||||
from openbb_provider.abstract.fetcher import DataType, ProviderDataType
|
||||
|
||||
|
||||
def get_querystring(items: dict, exclude: List[str]) -> str:
|
||||
"""Turns a dictionary into a querystring, excluding the keys in the exclude list.
|
||||
"""Turn a dictionary into a querystring, excluding the keys in the exclude list.
|
||||
|
||||
Parameters:
|
||||
-----------
|
||||
Parameters
|
||||
----------
|
||||
items: dict
|
||||
The dictionary to be turned into a querystring.
|
||||
|
||||
exclude: List[str]
|
||||
The keys to be excluded from the querystring.
|
||||
|
||||
Returns:
|
||||
--------
|
||||
Returns
|
||||
-------
|
||||
str
|
||||
The querystring.
|
||||
|
||||
"""
|
||||
for item in exclude:
|
||||
items.pop(item)
|
||||
@@ -35,6 +33,7 @@ def get_querystring(items: dict, exclude: List[str]) -> str:
|
||||
def process(
|
||||
row: ProviderDataType, key: str, processors: Optional[Dict[str, Callable]] = None
|
||||
):
|
||||
"""Process a specific field."""
|
||||
if not processors:
|
||||
return getattr(row, key)
|
||||
if key not in processors:
|
||||
@@ -43,7 +42,7 @@ def process(
|
||||
|
||||
|
||||
def camel_to_snake(name: str) -> str:
|
||||
"Converts a camelCase string to snake_case."
|
||||
"""Convert a camelCase string to snake_case."""
|
||||
pattern = re.compile(r"(?<!^)(?=[A-Z])")
|
||||
return pattern.sub("_", name).lower()
|
||||
|
||||
@@ -54,6 +53,7 @@ def convert_schema(
|
||||
mapping: Dict[str, str],
|
||||
processors: Optional[Dict[str, Callable]] = None,
|
||||
):
|
||||
"""Convert a specific schema to a given new_schema."""
|
||||
mapped_fields = {
|
||||
value: process(row, key, processors) for key, value in mapping.items()
|
||||
}
|
||||
@@ -61,7 +61,7 @@ def convert_schema(
|
||||
|
||||
|
||||
def check_alias(field) -> bool:
|
||||
"Checks if a field has an alias."
|
||||
"""Check if a field has an alias."""
|
||||
alias = getattr(field, "alias")
|
||||
name = getattr(field, "name")
|
||||
return alias != name
|
||||
@@ -72,10 +72,10 @@ def data_transformer(
|
||||
new_schema: Type[DataType],
|
||||
processors: Optional[Dict[str, Callable]] = None,
|
||||
) -> Union[List[DataType], DataType]:
|
||||
"""Converts a specific data into the standardised version
|
||||
"""Convert a specific data into the standardised version.
|
||||
|
||||
Parameters:
|
||||
-----------
|
||||
Parameters
|
||||
----------
|
||||
data: Union[List[ProviderDataType], ProviderDataType]
|
||||
A list of pydantic schemas
|
||||
|
||||
@@ -85,11 +85,10 @@ def data_transformer(
|
||||
processors: Optional[Dict[str, str]]
|
||||
A dictionary with fields and custom processing functions
|
||||
|
||||
Returns:
|
||||
--------
|
||||
Returns
|
||||
-------
|
||||
List[DataType]
|
||||
A list of the newly formatted schemas
|
||||
|
||||
"""
|
||||
the_data = data[0] if isinstance(data, list) else data
|
||||
fields = the_data.__dict__.keys()
|
||||
|
||||
Reference in New Issue
Block a user