Commit b5c2d9bd authored by Ibrahim Ahmed's avatar Ibrahim Ahmed
Browse files

utils: Added credential parsing from separate file from settings.ini

parent 7e0ec65a
Loading
Loading
Loading
Loading
+1 −0
Changes for src/utils/__init__.py: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -7,3 +7,4 @@ abstract generic operations.
from .type_operations import *
from .training import *
from .logging import EmailHandler, RemoteHandler
from .credentials import get_credentials
+38 −0
Changes for src/utils/credentials.py: 38 added lines, 0 removed lines.
Original line number Diff line number Diff line
"""
Functions for reading and writing username/password
"""

import os
from configparser import ConfigParser
from typing import Tuple


def get_credentials(filename: str='bdxcredentials.ini', section: str='DEFAULT') \
    -> Tuple[str, str]:
    """
    Get username/password stored in ini file under the `src/` directory.__file__

    Parameters
    ----------
    filename : str, optional
        Name of the ini file, by default 'bdxcredentials.ini'
    section : str, optional
        The section containing username and password fields, by default 'DEFAULT'

    Returns
    -------
    Tuple[str, str]
        The username and password
    """
    src_path = os.path.dirname(os.path.abspath(__file__))
    path = os.path.join(src_path, '../', filename)
    try:
        cfg = ConfigParser()
        cfg.read(path)
        return cfg.get(section, 'username'), cfg.get(section, 'password')
    except Exception as err:
        raise Exception((f'Looking at path:\n\t{path}\n' 
                         'The credential file should exist in `src/` in the format:\n'
                         '[DEFAULT]\n'
                         'username = USERNAME\n'
                         'password = PASSWORD\n')) from err
+2 −2
Changes for src/utils/stats.py: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@
Statistical analysis functions.
"""


from typing import Iterable

import numpy as np
import pandas as pd
@@ -65,7 +65,7 @@ def mutual_information(df: pd.DataFrame, bins: int=32) -> np.ndarray:



def temporal_correlations(features, lags, targets=None) -> np.ndarray:
def temporal_correlations(features: np.ndarray, lags: Iterable, targets: np.ndarray=None) -> np.ndarray:
    targets = features if targets is None else targets
    numf = features.shape[1] if features.ndim == 2 else 1
    numt = targets.shape[1] if targets.ndim == 2 else 1