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

Fixed the date formatting errors due to update of pandas. related uni… #110

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def _prepare_weather_data(coordinates: List[GeoPosition], station_id, raw_ds):
var_name: (["coord", "time"], var.values)
for var_name, var in ds.data_vars.items()
}
timeline = ds.coords["date"].values
timeline = pd.DatetimeIndex(ds.coords["date"].values)

ds = xr.Dataset(
data_vars=data_dict,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ def _parse_raw_weather_data(self, raw_data: str) -> xr.Dataset:
dataframe_data = pd.DataFrame.from_dict(json_data, orient="columns")

conversion_dict = {
"date": "datetime64[ns]",
"hour": str,
"station_code": int,
}
Expand All @@ -262,6 +261,7 @@ def _parse_raw_weather_data(self, raw_data: str) -> xr.Dataset:
# KNMI measures the -th hour. (The 24th hour is from 23:00 to 00:00 the next day) We use 23:00 to indicate that.
dataframe_data["hour"] = dataframe_data["hour"] - 1
dataframe_data = dataframe_data.astype(conversion_dict)
dataframe_data["date"] = pd.to_datetime(dataframe_data["date"])

# Convert hours from time to timestamp
dataframe_data["timestamp"] = pd.to_timedelta(dataframe_data["hour"] + ":00:00")
Expand All @@ -284,7 +284,7 @@ def _prepare_weather_data(coordinates: List[GeoPosition], station_id, raw_ds):

# dict of data
data_dict = {var_name: (["coord", "time"], var.values) for var_name, var in ds.data_vars.items()}
timeline = ds.coords["date"].values
timeline = pd.DatetimeIndex(ds.coords["date"].values)

ds = xr.Dataset(
data_vars=data_dict,
Expand Down
2 changes: 1 addition & 1 deletion weather_provider_api/routers/weather/utils/date_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def parse_datetime(
if datetime_string is None:
return None

dt = pd.to_datetime(datetime_string, dayfirst=True, errors="coerce")
dt = pd.to_datetime(datetime_string, dayfirst=False, errors="coerce")

if pd.isnull(dt):
logger.exception("Error while parsing datetime string", input=datetime_string)
Expand Down