Skip to content

Commit

Permalink
preserve fuel in Flight.resample_and_fill
Browse files Browse the repository at this point in the history
  • Loading branch information
zebengberg committed Oct 29, 2024
1 parent aa3256c commit 0e46eb0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## v0.54.3 (unreleased)

### Fixes

- Ensure the fuel type is preserved when calling `Flight.resample_and_fill`.

## v0.54.2

### Features
Expand Down
2 changes: 1 addition & 1 deletion pycontrails/core/flight.py
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ def resample_and_fill(
msg = f"{msg} Pass 'keep_original_index=True' to keep the original index."
warnings.warn(msg)

return Flight(data=df, attrs=self.attrs)
return Flight(data=df, attrs=self.attrs, fuel=self.fuel)

def clean_and_resample(
self,
Expand Down
11 changes: 7 additions & 4 deletions tests/unit/test_flight.py
Original file line number Diff line number Diff line change
Expand Up @@ -1219,23 +1219,26 @@ def test_flight_slots(flight_fake: Flight) -> None:
flight_fake.foo = "bar"


@pytest.mark.parametrize("method", ["copy", "filter"])
@pytest.mark.parametrize("method", ["copy", "filter", "resample"])
def test_method_preserves_fuel(flight_fake: Flight, method: str) -> None:
"""Ensure fuel is preserved for the copy and filter methods."""
"""Ensure fuel is preserved for the copy, filter, and resample_and_fill methods."""

flight_fake.fuel = SAFBlend(15.0)

if method == "copy":
out = flight_fake.copy()
else:
assert method == "filter"
elif method == "filter":
mask = np.ones(len(flight_fake), dtype=bool)
mask[::3] = False
out = flight_fake.filter(mask)
else:
assert method == "resample"
out = flight_fake.resample_and_fill("50s")

assert isinstance(out, Flight)
assert hasattr(out, "fuel")
assert out.fuel is flight_fake.fuel
assert out.fuel == SAFBlend(15.0)


def test_resample_and_fill_short_flight() -> None:
Expand Down

0 comments on commit 0e46eb0

Please sign in to comment.