Skip to content

Commit

Permalink
Merge pull request #124 from lahdjirayhan/bugfix-range-coordinate
Browse files Browse the repository at this point in the history
Bugfix for `get_range_coordinates_air`
  • Loading branch information
Milind220 committed Apr 23, 2022
2 parents 646bc36 + 1fac121 commit c060779
Show file tree
Hide file tree
Showing 10 changed files with 21,974 additions and 254 deletions.
15 changes: 10 additions & 5 deletions src/ozone/ozone.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,9 @@ def _extract_forecast_data(self, data_obj: Any) -> pandas.DataFrame:
df.index = pandas.to_datetime(df.index)
return df

def _check_and_get_data_obj(self, r: requests.Response, **check_debug_info) -> dict:
def _check_and_get_data_obj(
self, r: requests.Response, **check_debug_info
) -> Union[dict, List[dict]]:
"""Get data object from API response and throw error if any is encouuntered
Args:
Expand All @@ -239,8 +241,8 @@ def _check_and_get_data_obj(self, r: requests.Response, **check_debug_info) -> d
city names to show it instead of just generic exception message.
Returns:
dict: The data object i.e. the `data` part of the API response,
in dictionary format (already JSON-ified).
Union[dict, List[dict]]: The data object i.e. the `data` part of the
API response, in dictionary or list format (already JSON-ified).
"""
self._check_status_code(r)
Expand All @@ -249,8 +251,11 @@ def _check_and_get_data_obj(self, r: requests.Response, **check_debug_info) -> d
status = response.get("status")
data = response.get("data")

if status == "ok" and isinstance(data, dict):
return data
if status == "ok":
if isinstance(data, dict) or isinstance(data, list):
# Only return data if status is ok and data is either dict or list.
# Otherwise it gets to exception raisers below.
return data

if isinstance(data, str):
if "Unknown station" in data:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ interactions:
Content-Type:
- application/json; charset=UTF-8
Date:
- Fri, 22 Apr 2022 01:27:05 GMT
- Fri, 22 Apr 2022 17:39:52 GMT
Server:
- nginx
Transfer-Encoding:
- chunked
Vary:
- Accept-Encoding
X-Gen-Time:
- "33.192\xC2\xB5s"
- "24.849\xC2\xB5s"
X-Powered-By:
- rxstreamer-waqi/1.3
content-length:
Expand Down
2,467 changes: 2,432 additions & 35 deletions tests/cassettes/test_get_range_coordinates_air/test_bad_data_format.yaml

Large diffs are not rendered by default.

2,467 changes: 2,432 additions & 35 deletions tests/cassettes/test_get_range_coordinates_air/test_column_expected_contents.yaml

Large diffs are not rendered by default.

2,467 changes: 2,432 additions & 35 deletions tests/cassettes/test_get_range_coordinates_air/test_column_types.yaml

Large diffs are not rendered by default.

2,467 changes: 2,432 additions & 35 deletions tests/cassettes/test_get_range_coordinates_air/test_excluded_params.yaml

Large diffs are not rendered by default.

Large diffs are not rendered by default.

7,403 changes: 7,368 additions & 35 deletions tests/cassettes/test_get_range_coordinates_air/test_output_formats.yaml

Large diffs are not rendered by default.

2,467 changes: 2,432 additions & 35 deletions tests/cassettes/test_get_range_coordinates_air/test_return_value_and_format.yaml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions tests/test_get_range_coordinates_air.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def test_column_expected_contents():
# Sanity check: make sure lat-lon are within range
assert (result["latitude"] > LOWER_BOUND[0]).all()
assert (result["latitude"] < UPPER_BOUND[0]).all()
assert (result["longitude"] < LOWER_BOUND[1]).all()
assert (result["longitude"] > UPPER_BOUND[1]).all()
assert (result["longitude"] > LOWER_BOUND[1]).all()
assert (result["longitude"] < UPPER_BOUND[1]).all()

# Range of coordinates: no city was given, hence city must all be nan
assert numpy.isnan(result["city"]).all()
Expand Down

0 comments on commit c060779

Please sign in to comment.