Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve get_city_forecast to pass tests #132

Merged
merged 2 commits into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/ozone/ozone.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,12 @@ def _extract_forecast_data(self, data_obj: Any) -> pandas.DataFrame:
dict_of_frames[pol] = pandas.DataFrame(lst).set_index("day")

df = pandas.concat(dict_of_frames, axis=1)

# Convert to numeric while making non-numerics nan,
# and then convert to float, just in case there's int
df = df.apply(lambda x: pandas.to_numeric(x, errors="coerce")).astype(float)
df.index = pandas.to_datetime(df.index)
df = df.reset_index().rename(columns={"day": "date"})
return df

def _check_and_get_data_obj(
Expand Down
13 changes: 5 additions & 8 deletions tests/test_get_city_forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,17 @@ def test_return_value_and_format():


@pytest.mark.vcr
def test_index_and_column_types():
def test_column_types():
result = api.get_city_forecast("london")

# The index contains date information
assert pd_types.is_datetime64_any_dtype(result.index)
# The date column contains date information
assert pd_types.is_datetime64_any_dtype(result["date"])

# Check that all pollutants and statistics are in column
# and are of float type
for param in ["pm25", "pm10", "o3", "uvi"]:
for stat in ["min", "max", "avg"]:
assert (param, stat) in result

# Check that all columns are of float type
for col in result:
assert pd_types.is_float_dtype(result[col])
assert pd_types.is_float_dtype(result[(param, stat)])


@pytest.mark.vcr
Expand Down