From ebd7849a51a5d9b5a7686495efc553dfa007c46b Mon Sep 17 00:00:00 2001 From: Max Hollmann Date: Fri, 28 Apr 2023 18:37:48 +0200 Subject: [PATCH 1/3] Add dataset parameter --- .github/workflows/main.yml | 2 +- src/blueskyapi/client.py | 6 +++++ test.py | 22 --------------- .../{client_test.py => test_client.py} | 27 +++++++++++++++++++ .../{errors_test.py => test_errors.py} | 0 5 files changed, 34 insertions(+), 23 deletions(-) delete mode 100644 test.py rename tests/blueskyapi/{client_test.py => test_client.py} (91%) rename tests/blueskyapi/{errors_test.py => test_errors.py} (100%) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 979728c..f7b7b6f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -120,7 +120,7 @@ jobs: - name: Setup poetry uses: abatilo/actions-poetry@v2.0.0 with: - poetry-version: "1.3.1" + poetry-version: "1.4.2" - name: Authenticate poetry run: poetry config pypi-token.pypi ${{ secrets.PYPI_API_TOKEN }} diff --git a/src/blueskyapi/client.py b/src/blueskyapi/client.py index cc916bf..2757384 100644 --- a/src/blueskyapi/client.py +++ b/src/blueskyapi/client.py @@ -73,6 +73,7 @@ def latest_forecast( lon: float, forecast_distances: Iterable[int] = None, columns: Iterable[str] = None, + dataset: Optional[str] = None, ) -> pd.DataFrame: """Obtain the latest forecast. @@ -80,6 +81,7 @@ def latest_forecast( :param lon: Longitude for which to fetch the forecast. :param forecast_distances: Forecast distances to fetch data for (hours from ``forecast_moment``). :param columns: Which variables to fetch (see `this page for available variables `_). + :param dataset: Which dataset to fetch data from (only for users on the Professional plan). """ response = self._get( "/forecasts/latest", @@ -90,6 +92,7 @@ def latest_forecast( forecast_distances, "forecast_distances" ), columns=_prepare_comma_separated_list(columns, "columns"), + dataset=dataset, ), ) return _create_dataframe(response) @@ -102,6 +105,7 @@ def forecast_history( max_forecast_moment: Optional[Union[datetime, str]] = None, forecast_distances: Optional[Iterable[int]] = None, columns: Optional[Iterable[str]] = None, + dataset: Optional[str] = None, ) -> pd.DataFrame: """Obtain historical forecasts. @@ -111,6 +115,7 @@ def forecast_history( :param max_forecast_moment: The last forecast moment to include. :param forecast_distances: Forecast distances to return data for (hours from ``forecast_moment``). :param columns: Which variables to fetch (see `this page for available variables `_). + :param dataset: Which dataset to fetch data from (only for users on the Professional plan). """ response = self._get( "/forecasts/history", @@ -127,6 +132,7 @@ def forecast_history( forecast_distances, "forecast_distances" ), columns=_prepare_comma_separated_list(columns, "columns"), + dataset=dataset, ), ) return _create_dataframe(response) diff --git a/test.py b/test.py deleted file mode 100644 index fb72250..0000000 --- a/test.py +++ /dev/null @@ -1,22 +0,0 @@ -import blueskyapi - - -client = blueskyapi.Client() - -d = client.latest_forecast( - 53, - 10, - columns=["wind_u_at_100m"], - forecast_distances=[0, 24], -) -print(d) - - -d = client.forecast_history( - 53, - 10, - columns=["wind_u_at_100m"], - forecast_distances=[0, 24], - min_forecast_moment="2021-06-01 00:00", -) -print(d) diff --git a/tests/blueskyapi/client_test.py b/tests/blueskyapi/test_client.py similarity index 91% rename from tests/blueskyapi/client_test.py rename to tests/blueskyapi/test_client.py index 518d204..3e492be 100644 --- a/tests/blueskyapi/client_test.py +++ b/tests/blueskyapi/test_client.py @@ -134,6 +134,19 @@ def test_result(client): ) assert np.all(result.some_column == [5]) + def describe_dataset(): + @responses.activate + def with_valid(client): + add_api_response( + "/forecasts/latest" + "?lat=53.5&lon=13.5&dataset=the-dataset" + ) + client.latest_forecast( + 53.5, + 13.5, + dataset="the-dataset", + ) + @pytest.mark.vcr() def test_integration(client): result = client.latest_forecast(53.5, 13.5) @@ -211,6 +224,20 @@ def with_none(client): max_forecast_moment=None, ) + def describe_dataset(): + @responses.activate + def with_valid(client): + add_api_response( + "/forecasts/history" + "?lat=53.5&lon=13.5&dataset=the-dataset" + ) + client.forecast_history( + 53.5, + 13.5, + dataset="the-dataset", + ) + + @pytest.mark.vcr() def test_integration(client): min_moment = datetime(2021, 12, 27, 18, 0) diff --git a/tests/blueskyapi/errors_test.py b/tests/blueskyapi/test_errors.py similarity index 100% rename from tests/blueskyapi/errors_test.py rename to tests/blueskyapi/test_errors.py From d1c3364e8fde3fc25066c663e5868fd71eeac461 Mon Sep 17 00:00:00 2001 From: Max Hollmann Date: Fri, 28 Apr 2023 18:55:24 +0200 Subject: [PATCH 2/3] Use coveralls github action --- .github/workflows/main.yml | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f7b7b6f..64ccc16 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -81,12 +81,11 @@ jobs: - name: Run pytest run: poetry run coverage run -m pytest -p no:sugar - - name: Upload coverage data to coveralls.io - run: poetry run coveralls --service=github - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - COVERALLS_FLAG_NAME: ${{ matrix.test-name }} - COVERALLS_PARALLEL: true + - name: Coveralls Parallel + uses: coverallsapp/github-action@v2 + with: + flag-name: run-${{ join(matrix.*, '-') }} + parallel: true coveralls: name: Indicate completion to coveralls.io @@ -95,11 +94,10 @@ jobs: container: python:3-slim steps: - name: Finished - run: | - pip3 install --upgrade coveralls - coveralls --service=github --finish - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + uses: coverallsapp/github-action@v2 + with: + parallel-finished: true + carryforward: "run-1,run-2" publish: name: Build package and publish to PyPI From b9172ac44c592a847054601d3ebc42a3999c660f Mon Sep 17 00:00:00 2001 From: Max Hollmann Date: Sat, 29 Apr 2023 14:06:58 +0200 Subject: [PATCH 3/3] Temporarily disable coveralls --- .github/workflows/main.yml | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 64ccc16..e2fc1f9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -81,23 +81,24 @@ jobs: - name: Run pytest run: poetry run coverage run -m pytest -p no:sugar - - name: Coveralls Parallel - uses: coverallsapp/github-action@v2 - with: - flag-name: run-${{ join(matrix.*, '-') }} - parallel: true - - coveralls: - name: Indicate completion to coveralls.io - needs: tests - runs-on: ubuntu-latest - container: python:3-slim - steps: - - name: Finished - uses: coverallsapp/github-action@v2 - with: - parallel-finished: true - carryforward: "run-1,run-2" + # Temporarily disabled because of bug on windows tests + # - name: Coveralls Parallel + # uses: coverallsapp/github-action@v2 + # with: + # flag-name: run-${{ join(matrix.*, '-') }} + # parallel: true + + # coveralls: + # name: Indicate completion to coveralls.io + # needs: tests + # runs-on: ubuntu-latest + # container: python:3-slim + # steps: + # - name: Finished + # uses: coverallsapp/github-action@v2 + # with: + # parallel-finished: true + # carryforward: "run-1,run-2" publish: name: Build package and publish to PyPI