From 6fb6ee8523d43976570e473028a5425c5c353275 Mon Sep 17 00:00:00 2001 From: Marina Kan Date: Wed, 23 Oct 2024 11:12:03 +0100 Subject: [PATCH 1/9] Rename folders --- {impc_api_helper => impc_module}/CONTRIBUTING.md | 0 {impc_api_helper => impc_module}/LICENSE | 0 {impc_api_helper => impc_module}/MANIFEST.in | 0 {impc_api_helper => impc_module}/README.md | 0 .../impc_api_helper => impc_module/impc_api}/__init__.py | 0 .../impc_api}/batch_solr_request.py | 0 .../impc_api_helper => impc_module/impc_api}/solr_request.py | 0 {impc_api_helper/impc_api_helper => impc_module/impc_api}/temp.py | 0 .../impc_api_helper => impc_module/impc_api}/utils/__init__.py | 0 .../impc_api}/utils/core_fields.json | 0 .../impc_api_helper => impc_module/impc_api}/utils/validators.py | 0 .../impc_api_helper => impc_module/impc_api}/utils/warnings.py | 0 {impc_api_helper => impc_module}/pyproject.toml | 0 {impc_api_helper => impc_module}/pytest.ini | 0 {impc_api_helper => impc_module}/setup.py | 0 {impc_api_helper => impc_module}/tests/__init__.py | 0 {impc_api_helper => impc_module}/tests/test_batch_solr_request.py | 0 {impc_api_helper => impc_module}/tests/test_helpers.py | 0 {impc_api_helper => impc_module}/tests/test_solr_request.py | 0 19 files changed, 0 insertions(+), 0 deletions(-) rename {impc_api_helper => impc_module}/CONTRIBUTING.md (100%) rename {impc_api_helper => impc_module}/LICENSE (100%) rename {impc_api_helper => impc_module}/MANIFEST.in (100%) rename {impc_api_helper => impc_module}/README.md (100%) rename {impc_api_helper/impc_api_helper => impc_module/impc_api}/__init__.py (100%) rename {impc_api_helper/impc_api_helper => impc_module/impc_api}/batch_solr_request.py (100%) rename {impc_api_helper/impc_api_helper => impc_module/impc_api}/solr_request.py (100%) rename {impc_api_helper/impc_api_helper => impc_module/impc_api}/temp.py (100%) rename {impc_api_helper/impc_api_helper => impc_module/impc_api}/utils/__init__.py (100%) rename {impc_api_helper/impc_api_helper => impc_module/impc_api}/utils/core_fields.json (100%) rename {impc_api_helper/impc_api_helper => impc_module/impc_api}/utils/validators.py (100%) rename {impc_api_helper/impc_api_helper => impc_module/impc_api}/utils/warnings.py (100%) rename {impc_api_helper => impc_module}/pyproject.toml (100%) rename {impc_api_helper => impc_module}/pytest.ini (100%) rename {impc_api_helper => impc_module}/setup.py (100%) rename {impc_api_helper => impc_module}/tests/__init__.py (100%) rename {impc_api_helper => impc_module}/tests/test_batch_solr_request.py (100%) rename {impc_api_helper => impc_module}/tests/test_helpers.py (100%) rename {impc_api_helper => impc_module}/tests/test_solr_request.py (100%) diff --git a/impc_api_helper/CONTRIBUTING.md b/impc_module/CONTRIBUTING.md similarity index 100% rename from impc_api_helper/CONTRIBUTING.md rename to impc_module/CONTRIBUTING.md diff --git a/impc_api_helper/LICENSE b/impc_module/LICENSE similarity index 100% rename from impc_api_helper/LICENSE rename to impc_module/LICENSE diff --git a/impc_api_helper/MANIFEST.in b/impc_module/MANIFEST.in similarity index 100% rename from impc_api_helper/MANIFEST.in rename to impc_module/MANIFEST.in diff --git a/impc_api_helper/README.md b/impc_module/README.md similarity index 100% rename from impc_api_helper/README.md rename to impc_module/README.md diff --git a/impc_api_helper/impc_api_helper/__init__.py b/impc_module/impc_api/__init__.py similarity index 100% rename from impc_api_helper/impc_api_helper/__init__.py rename to impc_module/impc_api/__init__.py diff --git a/impc_api_helper/impc_api_helper/batch_solr_request.py b/impc_module/impc_api/batch_solr_request.py similarity index 100% rename from impc_api_helper/impc_api_helper/batch_solr_request.py rename to impc_module/impc_api/batch_solr_request.py diff --git a/impc_api_helper/impc_api_helper/solr_request.py b/impc_module/impc_api/solr_request.py similarity index 100% rename from impc_api_helper/impc_api_helper/solr_request.py rename to impc_module/impc_api/solr_request.py diff --git a/impc_api_helper/impc_api_helper/temp.py b/impc_module/impc_api/temp.py similarity index 100% rename from impc_api_helper/impc_api_helper/temp.py rename to impc_module/impc_api/temp.py diff --git a/impc_api_helper/impc_api_helper/utils/__init__.py b/impc_module/impc_api/utils/__init__.py similarity index 100% rename from impc_api_helper/impc_api_helper/utils/__init__.py rename to impc_module/impc_api/utils/__init__.py diff --git a/impc_api_helper/impc_api_helper/utils/core_fields.json b/impc_module/impc_api/utils/core_fields.json similarity index 100% rename from impc_api_helper/impc_api_helper/utils/core_fields.json rename to impc_module/impc_api/utils/core_fields.json diff --git a/impc_api_helper/impc_api_helper/utils/validators.py b/impc_module/impc_api/utils/validators.py similarity index 100% rename from impc_api_helper/impc_api_helper/utils/validators.py rename to impc_module/impc_api/utils/validators.py diff --git a/impc_api_helper/impc_api_helper/utils/warnings.py b/impc_module/impc_api/utils/warnings.py similarity index 100% rename from impc_api_helper/impc_api_helper/utils/warnings.py rename to impc_module/impc_api/utils/warnings.py diff --git a/impc_api_helper/pyproject.toml b/impc_module/pyproject.toml similarity index 100% rename from impc_api_helper/pyproject.toml rename to impc_module/pyproject.toml diff --git a/impc_api_helper/pytest.ini b/impc_module/pytest.ini similarity index 100% rename from impc_api_helper/pytest.ini rename to impc_module/pytest.ini diff --git a/impc_api_helper/setup.py b/impc_module/setup.py similarity index 100% rename from impc_api_helper/setup.py rename to impc_module/setup.py diff --git a/impc_api_helper/tests/__init__.py b/impc_module/tests/__init__.py similarity index 100% rename from impc_api_helper/tests/__init__.py rename to impc_module/tests/__init__.py diff --git a/impc_api_helper/tests/test_batch_solr_request.py b/impc_module/tests/test_batch_solr_request.py similarity index 100% rename from impc_api_helper/tests/test_batch_solr_request.py rename to impc_module/tests/test_batch_solr_request.py diff --git a/impc_api_helper/tests/test_helpers.py b/impc_module/tests/test_helpers.py similarity index 100% rename from impc_api_helper/tests/test_helpers.py rename to impc_module/tests/test_helpers.py diff --git a/impc_api_helper/tests/test_solr_request.py b/impc_module/tests/test_solr_request.py similarity index 100% rename from impc_api_helper/tests/test_solr_request.py rename to impc_module/tests/test_solr_request.py From c12fa73e7a341ce3e2217cb4325665ee08f62f68 Mon Sep 17 00:00:00 2001 From: Marina Kan Date: Wed, 23 Oct 2024 11:19:21 +0100 Subject: [PATCH 2/9] Replace impc_api_helper with impc_api --- impc_module/CONTRIBUTING.md | 2 +- impc_module/MANIFEST.in | 2 +- impc_module/README.md | 6 +++--- impc_module/impc_api/batch_solr_request.py | 4 ++-- impc_module/impc_api/solr_request.py | 2 +- impc_module/impc_api/utils/validators.py | 2 +- impc_module/pyproject.toml | 4 ++-- impc_module/pytest.ini | 2 +- impc_module/setup.py | 4 ++-- impc_module/tests/test_batch_solr_request.py | 22 ++++++++++---------- impc_module/tests/test_solr_request.py | 2 +- 11 files changed, 26 insertions(+), 26 deletions(-) diff --git a/impc_module/CONTRIBUTING.md b/impc_module/CONTRIBUTING.md index 7e87df1..9117e04 100644 --- a/impc_module/CONTRIBUTING.md +++ b/impc_module/CONTRIBUTING.md @@ -12,7 +12,7 @@ The package is build using [setuptools](https://setuptools.pypa.io/en/latest/use ``` -from impc_api_helper import solr_request +from impc_api import solr_request num_found, df = solr_request( core='genotype-phenotype', params={ 'q': '*:*' 'rows': 10 diff --git a/impc_module/MANIFEST.in b/impc_module/MANIFEST.in index e833b2e..b2e6650 100644 --- a/impc_module/MANIFEST.in +++ b/impc_module/MANIFEST.in @@ -1 +1 @@ -include impc_api_helper/utils/core_fields.json \ No newline at end of file +include impc_api/utils/core_fields.json \ No newline at end of file diff --git a/impc_module/README.md b/impc_module/README.md index 197b76a..59054b4 100644 --- a/impc_module/README.md +++ b/impc_module/README.md @@ -1,5 +1,5 @@ -# IMPC_API_HELPER -`impc_api_helper` is a python package. +# IMPC_API +`impc_api` is a python package. The functions in this package are intended for use on a Jupyter Notebook. @@ -13,7 +13,7 @@ The functions in this package are intended for use on a Jupyter Notebook. The available functions can be imported as: ``` -from impc_api_helper import solr_request, batch_solr_request +from impc_api import solr_request, batch_solr_request ``` ## 1. Solr request diff --git a/impc_module/impc_api/batch_solr_request.py b/impc_module/impc_api/batch_solr_request.py index bdc4bec..77423c7 100644 --- a/impc_module/impc_api/batch_solr_request.py +++ b/impc_module/impc_api/batch_solr_request.py @@ -6,12 +6,12 @@ from .solr_request import solr_request from pathlib import Path import warnings -from impc_api_helper.utils.warnings import ( +from impc_api.utils.warnings import ( warning_config, RowsParamIgnored, UnsupportedDownloadFormatError, ) -from impc_api_helper.utils.validators import DownloadFormatValidator +from impc_api.utils.validators import DownloadFormatValidator # Initialise warning config diff --git a/impc_module/impc_api/solr_request.py b/impc_module/impc_api/solr_request.py index 01b7816..032d252 100644 --- a/impc_module/impc_api/solr_request.py +++ b/impc_module/impc_api/solr_request.py @@ -2,7 +2,7 @@ from tqdm import tqdm import pandas as pd import requests -from impc_api_helper.utils.validators import CoreParamsValidator +from impc_api.utils.validators import CoreParamsValidator # Display the whole dataframe <15 pd.set_option("display.max_rows", 15) diff --git a/impc_module/impc_api/utils/validators.py b/impc_module/impc_api/utils/validators.py index 665fbf2..4c5fc64 100644 --- a/impc_module/impc_api/utils/validators.py +++ b/impc_module/impc_api/utils/validators.py @@ -4,7 +4,7 @@ from pathlib import Path import warnings from dataclasses import dataclass, field -from impc_api_helper.utils.warnings import ( +from impc_api.utils.warnings import ( warning_config, InvalidCoreWarning, InvalidFieldWarning, diff --git a/impc_module/pyproject.toml b/impc_module/pyproject.toml index ee6fc5e..b4e6990 100644 --- a/impc_module/pyproject.toml +++ b/impc_module/pyproject.toml @@ -3,7 +3,7 @@ requires = ["setuptools"] build-backend = "setuptools.build_meta" [project] -name = "impc_api_helper" +name = "impc_api" version = "0.1.0" description = "A package to facilitate making API requests to the IMPC Solr API" authors = [ @@ -27,7 +27,7 @@ dev = [ ] [tool.setuptools.packages.find] -include = ["impc_api_helper", "impc_api_helper.*"] +include = ["impc_api", "impc_api.*"] [project.urls] "Homepage" = "https://github.com/mpi2/impc-data-api-workshop" diff --git a/impc_module/pytest.ini b/impc_module/pytest.ini index 9c2fb12..5383661 100644 --- a/impc_module/pytest.ini +++ b/impc_module/pytest.ini @@ -1,2 +1,2 @@ [pytest] -pythonpath = impc_api_helper \ No newline at end of file +pythonpath = impc_api \ No newline at end of file diff --git a/impc_module/setup.py b/impc_module/setup.py index 3307bf7..d684217 100644 --- a/impc_module/setup.py +++ b/impc_module/setup.py @@ -2,12 +2,12 @@ setup( - name='impc_api_helper', + name='impc_api', version='0.1.0', description='A package to facilitate making API request to the IMPC Solr API', author='MPI2, Marina Kan, Diego Pava', url='https://github.com/mpi2/impc-data-api-workshop', - packages=find_packages(include=["impc_api_helper", "impc_api_helper.*"]), + packages=find_packages(include=["impc_api", "impc_api.*"]), include_package_data=True, install_requires=[ 'pandas>=2.2.0', diff --git a/impc_module/tests/test_batch_solr_request.py b/impc_module/tests/test_batch_solr_request.py index a595efe..985ab33 100644 --- a/impc_module/tests/test_batch_solr_request.py +++ b/impc_module/tests/test_batch_solr_request.py @@ -1,7 +1,7 @@ import pytest from pathlib import Path from unittest.mock import patch, call, Mock -from impc_api_helper.batch_solr_request import ( +from impc_api.batch_solr_request import ( batch_solr_request, _batch_solr_generator, solr_request, @@ -9,7 +9,7 @@ _solr_downloader, _read_downloaded_file, ) -from impc_api_helper.utils.warnings import ( +from impc_api.utils.warnings import ( RowsParamIgnored, UnsupportedDownloadFormatError, ) @@ -21,7 +21,7 @@ # When rows is passed to batch solr request, a warning is raised. # Let's ignore this warning in all tests except the one that asserts the warning pytestmark = pytest.mark.filterwarnings( - "ignore::impc_api_helper.utils.warnings.RowsParamIgnored" + "ignore::impc_api.utils.warnings.RowsParamIgnored" ) @@ -51,7 +51,7 @@ def common_params(self): # solr_request will be mocked with different values for numFound, therefore it is passed as param @pytest.fixture def mock_solr_request(self, request): - with patch("impc_api_helper.batch_solr_request.solr_request") as mock: + with patch("impc_api.batch_solr_request.solr_request") as mock: # Mock expected return content of the solr_request (numFound and df) mock.return_value = (request.param, pd.DataFrame()) yield mock @@ -59,7 +59,7 @@ def mock_solr_request(self, request): # Fixture mocking _batch_to_df @pytest.fixture def mock_batch_to_df(self): - with patch("impc_api_helper.batch_solr_request._batch_to_df") as mock: + with patch("impc_api.batch_solr_request._batch_to_df") as mock: # Mock expected return content of the _batch_to_df (pd.DataFrame) mock.return_value = pd.DataFrame() yield mock @@ -157,13 +157,13 @@ def test_batch_solr_request_download_false_large_request( # Fixture mocking _batch_solr_generator @pytest.fixture def mock_batch_solr_generator(self): - with patch("impc_api_helper.batch_solr_request._batch_solr_generator") as mock: + with patch("impc_api.batch_solr_request._batch_solr_generator") as mock: yield mock # Fixture mocking _solr_downloader. Yields a tmp_path to write a file for the duration of the test. @pytest.fixture def mock_solr_downloader(self, tmp_path): - with patch("impc_api_helper.batch_solr_request._solr_downloader") as mock: + with patch("impc_api.batch_solr_request._solr_downloader") as mock: temp_dir = Path(tmp_path) / "temp_dir" temp_dir.mkdir() yield mock @@ -377,7 +377,7 @@ def test_batch_solr_request_multiple_fields( # Test the warning when params["rows"] is passed @pytest.mark.filterwarnings( - "default::impc_api_helper.utils.warnings.RowsParamIgnored" + "default::impc_api.utils.warnings.RowsParamIgnored" ) @pytest.mark.parametrize("mock_solr_request", [10000], indirect=True) def test_param_rows_warning(core, common_params, mock_solr_request): @@ -408,7 +408,7 @@ def mock_solr_request_generator(self, request): """Patches solr_request for _batch_to_df _batch_solr_generator producing a df dynamically. Creates a df in chunks (row by row) mocking incoming batches of responses. """ - with patch("impc_api_helper.batch_solr_request.solr_request") as mock: + with patch("impc_api.batch_solr_request.solr_request") as mock: # Call the generator data_generator = self.data_generator() @@ -473,7 +473,7 @@ def test_batch_to_df( # Fixture to mock the requests module @pytest.fixture def mock_requests_get(self, request): - with patch("impc_api_helper.batch_solr_request.requests.get") as mock_get: + with patch("impc_api.batch_solr_request.requests.get") as mock_get: # Capture the format of the response wt = request.param["wt"] mock_get.return_value.format = wt @@ -579,7 +579,7 @@ def test_batch_solr_generator( # Fixture to mock requests.get returning a status code. @pytest.fixture def mock_requests_get_error(self, request): - with patch("impc_api_helper.batch_solr_request.requests.get") as mock_get: + with patch("impc_api.batch_solr_request.requests.get") as mock_get: mock_get.return_value.status_code = request.param yield mock_get diff --git a/impc_module/tests/test_solr_request.py b/impc_module/tests/test_solr_request.py index b0df4ca..e806509 100644 --- a/impc_module/tests/test_solr_request.py +++ b/impc_module/tests/test_solr_request.py @@ -2,7 +2,7 @@ from unittest.mock import patch from solr_request import solr_request, _process_faceting from .test_helpers import check_url_status_code_and_params -from impc_api_helper.utils.warnings import InvalidCoreWarning, InvalidFieldWarning +from impc_api.utils.warnings import InvalidCoreWarning, InvalidFieldWarning class TestSolrRequest: From 5bf8c54c0114d587027447016a3796bc6888289b Mon Sep 17 00:00:00 2001 From: Marina Kan Date: Wed, 23 Oct 2024 11:25:31 +0100 Subject: [PATCH 3/9] Edit README --- impc_module/README.md | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/impc_module/README.md b/impc_module/README.md index 59054b4..b4e1d27 100644 --- a/impc_module/README.md +++ b/impc_module/README.md @@ -19,7 +19,9 @@ from impc_api import solr_request, batch_solr_request ## 1. Solr request The most basic request to the IMPC solr API ``` -num_found, df = solr_request( core='genotype-phenotype', params={ +num_found, df = solr_request( + core='genotype-phenotype', + params={ 'q': '*:*', 'rows': 10, 'fl': 'marker_symbol,allele_symbol,parameter_stable_id' @@ -32,25 +34,27 @@ num_found, df = solr_request( core='genotype-phenotype', params={ ``` num_found, df = solr_request( - core="genotype-phenotype", - params={ + core="genotype-phenotype", + params={ "q": "*:*", "rows": 0, "facet": "on", "facet.field": "zygosity", "facet.limit": 15, "facet.mincount": 1, - }, - ) + , + } +) ``` ### b. Solr request validation A common pitfall when writing a query is the misspelling of `core` and `fields` arguments. For this, we have included a `validate` argument that raises a warning when these values are not as expected. Note this does not prevent you from executing a query; it just alerts you to a potential issue. - #### Core validation ``` -num_found, df = solr_request( core='invalid_core', params={ +num_found, df = solr_request( + core='invalid_core', + params={ 'q': '*:*', 'rows': 10 }, @@ -58,12 +62,14 @@ num_found, df = solr_request( core='invalid_core', params={ ) > InvalidCoreWarning: Invalid core: "genotype-phenotyp", select from the available cores: -> dict_keys(['experiment', 'genotype-phenotype', 'impc_images', 'phenodigm', 'statistical-result'])) +> dict_keys(['experiment', 'genotype-phenotype', 'impc_images', 'phenodigm', 'statistical-result']) ``` #### Field list validation ``` -num_found, df = solr_request( core='genotype-phenotype', params={ +num_found, df = solr_request( + core='genotype-phenotype', + params={ 'q': '*:*', 'rows': 10, 'fl': 'invalid_field,marker_symbol,allele_symbol' @@ -126,7 +132,7 @@ Pass the list to the `field_list` param and specify the type of `fl` in `field_t ``` # List of gene symbols -genes = ["Zfp580","Firrm","Gpld1","Mbip"] +genes = ["Zfp580", "Firrm", "Gpld1", "Mbip"] df = batch_solr_request( core='genotype-phenotype', @@ -140,11 +146,11 @@ df = batch_solr_request( ) print(df.head()) ``` -This too can be downloaded +This can be downloaded too: ``` # List of gene symbols -genes = ["Zfp580","Firrm","Gpld1","Mbip"] +genes = ["Zfp580", "Firrm", "Gpld1", "Mbip"] df = batch_solr_request( core='genotype-phenotype', @@ -159,6 +165,3 @@ df = batch_solr_request( ) print(df.head()) ``` - - - From 0688a142cbdf1739ab106fdbfed128d157ee228b Mon Sep 17 00:00:00 2001 From: Marina Kan Date: Wed, 23 Oct 2024 11:36:46 +0100 Subject: [PATCH 4/9] Add docstring to the validators.py --- impc_module/impc_api/utils/validators.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/impc_module/impc_api/utils/validators.py b/impc_module/impc_api/utils/validators.py index 4c5fc64..2be08b0 100644 --- a/impc_module/impc_api/utils/validators.py +++ b/impc_module/impc_api/utils/validators.py @@ -1,9 +1,26 @@ -from pydantic import BaseModel, model_validator, field_validator +""" +This module provides validation for core fields and download formats using Pydantic models. + +Classes: + - ValidationJson: Loads and validates core fields from a JSON configuration file. + - CoreParamsValidator: Validates core names and associated fields (fl), issuing warnings for invalid inputs. + - DownloadFormatValidator: Validates the download format (wt) to ensure it is supported (json or csv). + +Functions: + - get_fields(fields: str) -> List[str]: Parses a comma-separated string of field names into a list. + +Custom Exceptions: + - InvalidCoreWarning: Raised for invalid core names. + - InvalidFieldWarning: Raised for unexpected field names. + - UnsupportedDownloadFormatError: Raised for unsupported download formats. +""" + import json -from typing import List, Dict -from pathlib import Path import warnings from dataclasses import dataclass, field +from pathlib import Path +from typing import List, Dict +from pydantic import BaseModel, model_validator, field_validator from impc_api.utils.warnings import ( warning_config, InvalidCoreWarning, @@ -14,7 +31,6 @@ # Initialise warning config warning_config() - # Dataclass for the json validator @dataclass class ValidationJson: From 61669ace88281336bd6c96030c3c5774f127e0b2 Mon Sep 17 00:00:00 2001 From: Marina Kan Date: Wed, 23 Oct 2024 11:43:30 +0100 Subject: [PATCH 5/9] Reorder libraries --- impc_module/impc_api/batch_solr_request.py | 14 +++++++------- impc_module/impc_api/solr_request.py | 6 +++--- impc_module/tests/test_batch_solr_request.py | 11 ++++++----- impc_module/tests/test_solr_request.py | 5 ++--- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/impc_module/impc_api/batch_solr_request.py b/impc_module/impc_api/batch_solr_request.py index 77423c7..c025847 100644 --- a/impc_module/impc_api/batch_solr_request.py +++ b/impc_module/impc_api/batch_solr_request.py @@ -1,23 +1,23 @@ -from IPython.display import display import json +import warnings +from pathlib import Path + import pandas as pd import requests from tqdm import tqdm -from .solr_request import solr_request -from pathlib import Path -import warnings +from IPython.display import display + +from impc_api.utils.validators import DownloadFormatValidator from impc_api.utils.warnings import ( warning_config, RowsParamIgnored, UnsupportedDownloadFormatError, ) -from impc_api.utils.validators import DownloadFormatValidator - +from .solr_request import solr_request # Initialise warning config warning_config() - def batch_solr_request( core, params, download=False, batch_size=5000, filename="batch_request" ): diff --git a/impc_module/impc_api/solr_request.py b/impc_module/impc_api/solr_request.py index 032d252..296214b 100644 --- a/impc_module/impc_api/solr_request.py +++ b/impc_module/impc_api/solr_request.py @@ -1,14 +1,14 @@ -from IPython.display import display -from tqdm import tqdm import pandas as pd import requests +from IPython.display import display +from tqdm import tqdm + from impc_api.utils.validators import CoreParamsValidator # Display the whole dataframe <15 pd.set_option("display.max_rows", 15) pd.set_option("display.max_columns", None) - # Create helper function def solr_request(core, params, silent=False, validate=False): """Performs a single Solr request to the IMPC Solr API. diff --git a/impc_module/tests/test_batch_solr_request.py b/impc_module/tests/test_batch_solr_request.py index 985ab33..f70b70f 100644 --- a/impc_module/tests/test_batch_solr_request.py +++ b/impc_module/tests/test_batch_solr_request.py @@ -1,6 +1,11 @@ -import pytest +import json from pathlib import Path from unittest.mock import patch, call, Mock + +import pandas as pd +import pytest +from pandas.testing import assert_frame_equal + from impc_api.batch_solr_request import ( batch_solr_request, _batch_solr_generator, @@ -13,10 +18,6 @@ RowsParamIgnored, UnsupportedDownloadFormatError, ) -import json -import pandas as pd -from pandas.testing import assert_frame_equal - # When rows is passed to batch solr request, a warning is raised. # Let's ignore this warning in all tests except the one that asserts the warning diff --git a/impc_module/tests/test_solr_request.py b/impc_module/tests/test_solr_request.py index e806509..c9a44ee 100644 --- a/impc_module/tests/test_solr_request.py +++ b/impc_module/tests/test_solr_request.py @@ -1,9 +1,8 @@ -import pytest from unittest.mock import patch +import pytest +from impc_api.utils.warnings import InvalidCoreWarning, InvalidFieldWarning from solr_request import solr_request, _process_faceting from .test_helpers import check_url_status_code_and_params -from impc_api.utils.warnings import InvalidCoreWarning, InvalidFieldWarning - class TestSolrRequest: """Test class for the Solr Request function From f013abf38cbe2ff677c64e5de0998f5923eef48e Mon Sep 17 00:00:00 2001 From: Marina Kan Date: Wed, 23 Oct 2024 11:54:30 +0100 Subject: [PATCH 6/9] Remove temp.py --- impc_module/impc_api/temp.py | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 impc_module/impc_api/temp.py diff --git a/impc_module/impc_api/temp.py b/impc_module/impc_api/temp.py deleted file mode 100644 index 1a7fe66..0000000 --- a/impc_module/impc_api/temp.py +++ /dev/null @@ -1,19 +0,0 @@ -from iterator_solr_request_2 import batch_solr_request -import pandas as pd - -markers = ['"Cthrc1"', '*11'] -df = batch_solr_request( - core="genotype-phenotype", - params={ - "q": "*:*", - "fl": "marker_symbol,mp_term_name,p_value", - 'field_list': markers, - 'field_type': 'marker_symbol' - }, - download=True, -) - -df = pd.read_json('genotype-phenotype.json', nrows=80000, lines=True) -# df = pd.read_csv('genotype-phenotype.csv', nrows=80000) -# df = pd.read_xml('genotype-phenotype.xml', parser='etree') -print(df.shape) From 06cb0cb11f65afcca27b18759522dd9644fcd0c7 Mon Sep 17 00:00:00 2001 From: dpavam <93325413+dpavam@users.noreply.github.com> Date: Wed, 23 Oct 2024 12:18:08 +0100 Subject: [PATCH 7/9] Update CONTRIBUTING.md --- impc_module/CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/impc_module/CONTRIBUTING.md b/impc_module/CONTRIBUTING.md index 9117e04..ddf847e 100644 --- a/impc_module/CONTRIBUTING.md +++ b/impc_module/CONTRIBUTING.md @@ -23,7 +23,7 @@ num_found, df = solr_request( core='genotype-phenotype', params={ ## Installing the package for development We use [pytest](https://docs.pytest.org/en/stable/) for testing. To install in dev mode follow [stepts 1 and 2](#installing-the-package-for-use) above and then: -3. Install the package running `pip install '.[dev]'` +3. Install the package running `pip install -e .` This should install `pytest` and enable you to run tests: ``` From 9bd469fee492fe016588d350d9f16e40e9565ce9 Mon Sep 17 00:00:00 2001 From: Marina Kan <113850522+marinak-ebi@users.noreply.github.com> Date: Wed, 23 Oct 2024 12:59:19 +0100 Subject: [PATCH 8/9] Fix typo impc_module/README.md Co-authored-by: dpavam <93325413+dpavam@users.noreply.github.com> --- impc_module/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/impc_module/README.md b/impc_module/README.md index b4e1d27..14de016 100644 --- a/impc_module/README.md +++ b/impc_module/README.md @@ -42,7 +42,6 @@ num_found, df = solr_request( "facet.field": "zygosity", "facet.limit": 15, "facet.mincount": 1, - , } ) ``` From fd7ba995be14d763e582c1feda0552e4e1c8f89a Mon Sep 17 00:00:00 2001 From: Marina Kan <113850522+marinak-ebi@users.noreply.github.com> Date: Wed, 23 Oct 2024 13:02:35 +0100 Subject: [PATCH 9/9] Update impc_module/README.md Co-authored-by: dpavam <93325413+dpavam@users.noreply.github.com> --- impc_module/README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/impc_module/README.md b/impc_module/README.md index 14de016..0cdc541 100644 --- a/impc_module/README.md +++ b/impc_module/README.md @@ -2,7 +2,13 @@ `impc_api` is a python package. The functions in this package are intended for use on a Jupyter Notebook. +1. **Create a virtual environment (optional but recommended)**: +On Mac: + `python3 -m venv .venv` + `source .venv/bin/activate` +3. **Install the package running**: `pip install impc_api` +4. **Try it out**: Create a [Jupyter Notebook](https://jupyter.org/install#jupyter-notebook) and try some of the examples below: ## Installing the package for the first time 1. Clone the repository and navigate into it. Navigate into the package name until you can see `setup.py` and `pyproject.toml` 2. Run `python3 -m build`, this builds the package, a couple of new files/folders will appear.