Skip to content

Commit

Permalink
Fix breaking changes with polars 0.19.6
Browse files Browse the repository at this point in the history
  • Loading branch information
gutzbenj committed Oct 7, 2023
1 parent 5e1310f commit 177ffc5
Show file tree
Hide file tree
Showing 41 changed files with 357 additions and 274 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Development
***********

- Fix multiple issues with DwdObservationRequest API
- Raise minimum version of polars to 0.19.6 due to breaking changes

0.61.0 (06.10.2023)
*******************
Expand Down
4 changes: 2 additions & 2 deletions docs/img/readme_img.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ def create_temperature_ts_plot():
parameter="temperature_air_mean_200", resolution="daily", period="historical"
).filter_by_name("Hohenpeissenberg")
df = stations.values.all().df
df_annual = df.groupby(pl.col("date").dt.year(), maintain_order=True).agg(pl.col("value").mean().alias("value"))
df_annual = df.group_by(pl.col("date").dt.year(), maintain_order=True).agg(pl.col("value").mean().alias("value"))
df_annual = df_annual.with_columns(
pl.col("date").cast(str).str.strptime(datatype=pl.Datetime, fmt="%Y"), pl.col("value").mean().alias("mean")
pl.col("date").cast(str).str.to_datetime("%Y"), pl.col("value").mean().alias("mean")
)
fig, ax = plt.subplots(tight_layout=True)
df.to_pandas().plot("date", "value", ax=ax, color="blue", label="Tmean,daily", legend=False)
Expand Down
4 changes: 2 additions & 2 deletions example/observations_station_gaussian_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def __init__(self, station_data: StationsResult):

def get_valid_data(self, result_values: pl.DataFrame) -> pl.DataFrame:
valid_data_lst = []
for _, group in result_values.groupby(pl.col("date").dt.year()):
for _, group in result_values.group_by(pl.col("date").dt.year()):
if self.validate_yearly_data(group):
valid_data_lst.append(group)

Expand All @@ -110,7 +110,7 @@ def make_composite_yearly_model(self, valid_data: pl.DataFrame) -> Tuple[Gaussia
index_per_year = x.max() / number_of_years

pars, composite_model = None, None
for year, group in valid_data.groupby(pl.col("date").dt.year(), maintain_order=True):
for year, group in valid_data.group_by(pl.col("date").dt.year(), maintain_order=True):
gmod = GaussianModel(prefix=f"g{year}_")
if pars is None:
pars = gmod.make_params()
Expand Down
2 changes: 1 addition & 1 deletion example/wetterdienst_notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@
" agg_df = group.groupby(pl.col(\"date\").dt.year(), maintain_order=True).agg([pl.col(\"value\").mean()])\n",
" agg_df = agg_df.select(\n",
" pl.lit(parameter).alias(\"parameter\"),\n",
" pl.col(\"date\").cast(pl.Utf8).str.strptime(datatype=pl.Datetime, fmt=\"%Y\"),\n",
" pl.col(\"date\").cast(pl.Utf8).str.to_datetime(\"%Y\"),\n",
" pl.col(\"value\"),\n",
" )\n",
" data.append(agg_df)\n",
Expand Down
127 changes: 62 additions & 65 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ numpy = ">=1.22,<1.27"
pandas = ">=2,<2.2"
Pint = ">=0.17,<0.23"
platformdirs = "<4"
polars = ">=0.16,<0.20"
polars = ">=0.19.6,<0.20"
pyarrow = ">=13,<14"
pypdf = ">=3.12.1,<3.17"
python-dateutil = "<3"
Expand Down
6 changes: 3 additions & 3 deletions tests/core/timeseries/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ def test_export_duckdb(settings_si_false, tmp_path):
settings=settings_si_false,
).filter_by_station_id(station_id=[1048])
filename = tmp_path.joinpath("test.duckdb")
df = request.values.all().df
df = request.values.all().df.sort(["parameter", "date"])
ExportMixin(df=df).to_target(f"duckdb:///{filename}?table=testdrive")
connection = duckdb.connect(str(filename), read_only=True)
cursor = connection.cursor()
Expand All @@ -624,9 +624,9 @@ def test_export_duckdb(settings_si_false, tmp_path):
assert results[300_000] == (
"01048",
"climate_summary",
"temperature_air_max_200",
"temperature_air_min_200",
dt.datetime(1939, 7, 26),
21.0,
10.0,
1.0,
)

Expand Down
Loading

0 comments on commit 177ffc5

Please sign in to comment.