Skip to content

Commit 74fc76d

Browse files
committed
Fixes #51 - 1D resampling fix for custom mass names
1 parent 06fdbf1 commit 74fc76d

File tree

5 files changed

+16
-6
lines changed

5 files changed

+16
-6
lines changed

CHANGELOG.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
Geomet 0.4.11 (2025-01-25)
2+
==========================
3+
4+
Bugfix
5+
------
6+
7+
- 1D resampling fix for custom mass names (#51)
8+
9+
110
Geomet 0.4.10 (2025-01-23)
211
==========================
312

elphick/geomet/interval_sample.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,7 @@ def resample_1d(self, interval_edges: Union[Iterable, int],
585585
df_upsampled: pd.DataFrame = mass_preserving_interp(self.mass_data,
586586
interval_edges=interval_edges, precision=precision,
587587
include_original_edges=include_original_edges,
588+
mass_wet=None, mass_dry=self.mass_dry_var,
588589
interval_data_as_mass=True)
589590

590591
obj: IntervalSample = IntervalSample(df_upsampled, name=self.name, moisture_in_scope=False,

elphick/geomet/utils/interp.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
def mass_preserving_interp(df_intervals: pd.DataFrame, interval_edges: Union[Iterable, int],
1111
include_original_edges: bool = True, precision: Optional[int] = None,
12-
mass_wet: str = 'mass_wet', mass_dry: str = 'mass_dry',
12+
mass_wet: Optional[str] = 'mass_wet', mass_dry: str = 'mass_dry',
1313
interval_data_as_mass: bool = False) -> pd.DataFrame:
1414
"""Interpolate with zero mass loss using pchip
1515
@@ -81,7 +81,7 @@ def mass_preserving_interp(df_intervals: pd.DataFrame, interval_edges: Union[Ite
8181
# if the new grid extrapolates (on the coarse side), mass will be lost, so we assume that when extrapolating.
8282
# the mass in the extrapolated fractions is zero. By inserting these records the spline will conform.
8383
x_extra = grid_vals[grid_vals > mass_cum.index.max()]
84-
if x_extra:
84+
if len(x_extra) > 0:
8585
cum_max: pd.Series = mass_cum.iloc[-1, :]
8686
mass_cum = mass_cum.reindex(index=mass_cum.index.append(pd.Index(x_extra))) # reindex to enable insert
8787
mass_cum.loc[x_extra, :] = cum_max.values
@@ -180,7 +180,8 @@ def mass_preserving_interp_2d(intervals: pd.DataFrame, interval_edges: dict[str,
180180
# proportion the dim_1 interpolated values by the dim_2 recovery
181181
new_vals: pd.DataFrame = dim_2_deportment.mul(filtered_intervals_mass.loc[dim_1_interp_interval].values)
182182
# create a multiindex by combining the dim_1 and dim_2 intervals
183-
new_index = pd.MultiIndex.from_arrays([pd.IntervalIndex([dim_1_interp_interval] * len(new_vals)), new_vals.index])
183+
new_index = pd.MultiIndex.from_arrays(
184+
[pd.IntervalIndex([dim_1_interp_interval] * len(new_vals)), new_vals.index])
184185
new_vals.index = new_index
185186
chunks.append(new_vals)
186187

@@ -190,4 +191,3 @@ def mass_preserving_interp_2d(intervals: pd.DataFrame, interval_edges: dict[str,
190191
# convert to composition
191192
res = mass_to_composition(res, mass_dry=mass_dry)
192193
return res
193-

elphick/geomet/utils/pandas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def composition_to_mass(df: pd.DataFrame,
8888
df: The pd.DataFrame containing mass. H2O if provided will be ignored. All columns other than the
8989
mass_wet and mass_dry are assumed to be `additive`, that is, dry mass weighting is valid.
9090
Assumes composition is in %w/w units.
91-
mass_wet: The wet mass column, optional. If not provided, it's assumed to be equal to mass_dry.
91+
mass_wet: The wet mass column, optional.
9292
mass_dry: The dry mass column, not optional. Consider solve_mass_moisture prior to this call if needed.
9393
moisture_column_name: if mass_wet is provided, the resultant moisture will be returned with this column name.
9494
If None, and moisture is detected in the input, that column name will be used instead.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[tool.poetry]
22
name = "geometallurgy"
33
packages = [{ include = "elphick/geomet" }]
4-
version = "0.4.10"
4+
version = "0.4.11"
55
description = "Tools for the geometallurgist"
66
authors = ["Greg <11791585+elphick@users.noreply.github.com>"]
77
repository = "https://github.com/elphick/geometallurgy"

0 commit comments

Comments
 (0)