diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 304a3a0..13e27ef 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.4.0 hooks: - - id: end-of-file-fixer - id: check-docstring-first - id: check-yaml diff --git a/README.md b/README.md index b3153f4..4e692a8 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # pycot -[![PyPI version](https://d25lcipzij17d.cloudfront.net/badge.svg?id=py&r=r&ts=1683906897&type=6e&v=0.1.1&x2=0)](https://badge.fury.io/py/pycot-reports) +[![PyPI version](https://d25lcipzij17d.cloudfront.net/badge.svg?id=py&r=r&ts=1683906897&type=6e&v=0.1.2&x2=0)](https://badge.fury.io/py/pycot-reports) [![License: MIT](https://img.shields.io/badge/License-MIT-red.svg)](https://github.com/philsv/pycot/blob/main/LICENSE) [![Weekly Downloads](https://static.pepy.tech/personalized-badge/pycot-reports?period=week&units=international_system&left_color=grey&right_color=blue&left_text=downloads/week)](https://pepy.tech/project/pycot-reports) [![Monthly Downloads](https://static.pepy.tech/personalized-badge/pycot-reports?period=month&units=international_system&left_color=grey&right_color=blue&left_text=downloads/month)](https://pepy.tech/project/pycot-reports) diff --git a/pycot/config.py b/pycot/config.py index 0b0f2a7..268446a 100644 --- a/pycot/config.py +++ b/pycot/config.py @@ -6,25 +6,20 @@ def open_json(path: Path) -> dict: - """ - Opens a json file. - - Returns: - The content as a dictionary. - """ + """Opens a json file.""" with open(path, "r") as f: data = json.load(f) return data class Settings(BaseSettings): - """ - Settings for the pycot package. - """ + """Settings for the pycot package.""" BASE_PATH: Path = Path(__file__).parent.parent FORMAT_COLUMNS_PATH: Path = BASE_PATH / "pycot" / "store" / "format_columns.json" - COT_REPORTS_DATA_PATH: Path = BASE_PATH / "pycot" / "store" / "cot_reports_data.json" + COT_REPORTS_DATA_PATH: Path = ( + BASE_PATH / "pycot" / "store" / "cot_reports_data.json" + ) CONTRACT_NAMES_PATH: Path = BASE_PATH / "pycot" / "store" / "contract_names.json" FORMAT_COLUMNS: dict = open_json(FORMAT_COLUMNS_PATH) @@ -34,9 +29,7 @@ class Settings(BaseSettings): @lru_cache() def get_settings() -> Settings: - """ - Cache the settings object to avoid reading the environment variables - """ + """Cache the settings object to avoid reading the environment variables.""" return Settings() diff --git a/pycot/exceptions.py b/pycot/exceptions.py index 8d9d4c1..a7dcbff 100644 --- a/pycot/exceptions.py +++ b/pycot/exceptions.py @@ -1,4 +1,2 @@ class InvalidReportType(Exception): """Raised when the report type is not valid""" - - pass diff --git a/pycot/reports.py b/pycot/reports.py index 3afcb6c..996f3da 100644 --- a/pycot/reports.py +++ b/pycot/reports.py @@ -23,12 +23,9 @@ def format_dataframe( names: Union[list, tuple], columns: Union[list, tuple], ) -> pd.DataFrame: - """ - Helper function to format the data retrieved from the CFTC website. - """ - df = data.reindex( - columns=columns - ) # Limit the columns to the ones we need (please adjust to your liking in format_columns.json) + """Helper function to format the data retrieved from the CFTC website.""" + # Limit the columns to the ones we need (can be adjusted in format_columns.json) + df = data.reindex(columns=columns) df = df.rename(columns=dict(zip(columns, names))) df["Date"] = pd.to_datetime(df["Date"]) df = df.set_index(["Date", "Contract Name"]) @@ -43,9 +40,7 @@ def get_contract( df: pd.DataFrame, contract_name: Union[str, tuple], ) -> pd.DataFrame: - """ - Retrieves the Commitment of Traders Reports data for a specific contract or list of contracts. - """ + """Retrieves the Commitment of Traders Reports data for a specific contract or list of contracts.""" if isinstance(contract_name, str): return df[df["Contract Name"] == contract_name] @@ -97,9 +92,7 @@ def extract_text_file_to_dataframe( response: requests.models.Response, text_file: str, ) -> pd.DataFrame: - """ - Unzips the text file from an archive and returns a pandas DataFrame. - """ + """Unzips the text file from an archive and returns a pandas DataFrame.""" with tempfile.TemporaryDirectory() as tmpdirname: zip_path = os.path.join(tmpdirname, "archive.zip") @@ -361,7 +354,7 @@ def financial_report( df["Leveraged Money Short"] = df["Leveraged Money Short"] * -1 df = df.sort_index()[::-1] return df - + def list_available_contracts( self, ) -> np.ndarray: @@ -396,7 +389,7 @@ def list_available_contracts( "traders_in_financial_futures_futopt", ]: df = self.financial_report - + available_contracts = df["Contract Name"].unique() return np.sort(available_contracts) diff --git a/pycot/version.py b/pycot/version.py index 485f44a..b3f4756 100644 --- a/pycot/version.py +++ b/pycot/version.py @@ -1 +1 @@ -__version__ = "0.1.1" +__version__ = "0.1.2" diff --git a/setup.py b/setup.py index d8fe202..17e3a5c 100644 --- a/setup.py +++ b/setup.py @@ -16,6 +16,7 @@ license="MIT", author="philsv", author_email="frphsv@gmail.com", + description="Python Library for interacting with the CFTC Commitment of Traders reports.", long_description=long_description, long_description_content_type="text/markdown", keywords=["commitment of traders", "cot data", "cftc", "python"], diff --git a/tests/test_reports.py b/tests/test_reports.py index ff99d36..3e7039c 100644 --- a/tests/test_reports.py +++ b/tests/test_reports.py @@ -35,6 +35,7 @@ ], ) def test_individual_reports(report_type, contract_name): + """Test the individual reports.""" cot = CommitmentsOfTraders(report_type) df = cot.report(contract_name) assert isinstance(df, pd.DataFrame) @@ -49,6 +50,7 @@ def test_individual_reports(report_type, contract_name): ], ) def test_list_available_contracts(report_type): + """Test the list_available_contracts function.""" cot = CommitmentsOfTraders(report_type) contracts = cot.list_available_contracts() assert isinstance(contracts, np.ndarray) @@ -72,6 +74,7 @@ def test_list_available_contracts(report_type): ], ) def test_cot_report(report_type, contract_1, contract_2): + """Test the cot report function to retrieve data from the same report multiple times.""" start_time_1 = time.perf_counter() cot = CommitmentsOfTraders(report_type) df_1 = cot.report(contract_1)