Skip to content

Commit

Permalink
fix ruff and change T to min in pandas timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
xoolive committed Dec 13, 2024
1 parent aeddc12 commit bf198dc
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/traffic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from . import visualize # noqa: F401

__version__ = version("traffic")
__all__ = ["config_dir", "config_file", "cache_dir", "tqdm_style"]
__all__ = ["cache_dir", "config_dir", "config_file", "tqdm_style"]

# Set up the library root logger
_log = logging.getLogger(__name__)
Expand Down
8 changes: 4 additions & 4 deletions src/traffic/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ def silent_tqdm(


__all__ = [
"Airspace",
"Flight",
"FlightIterator",
"Traffic",
"Airspace",
"StateVectors",
"FlightPlan",
"LazyTraffic",
"loglevel",
"StateVectors",
"Traffic",
"faulty_flight",
"loglevel",
"tqdm",
]

Expand Down
6 changes: 3 additions & 3 deletions src/traffic/core/traffic.py
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ def longer_than( # type: ignore
def max_split( # type: ignore
self,
/,
value: Union[int, str] = "10T",
value: Union[int, str] = "10 min",
unit: Optional[str] = None,
key: str = "duration",
): ...
Expand All @@ -888,11 +888,11 @@ def apply_segments( # type: ignore
): ...

@lazy_evaluation()
def apply_time(self, /, freq="1T", merge=True, **kwargs): # type: ignore
def apply_time(self, /, freq="1 min", merge=True, **kwargs): # type: ignore
...

@lazy_evaluation()
def agg_time(self, /, freq="1T", merge=True, **kwargs): # type: ignore
def agg_time(self, /, freq="1 min", merge=True, **kwargs): # type: ignore
...

@lazy_evaluation()
Expand Down
12 changes: 6 additions & 6 deletions src/traffic/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,24 @@
# Parse configuration and input specific parameters in below classes

__all__ = [
"AllFT",
"Navaids",
"aircraft",
"airports",
"airways",
"navaids",
"runways",
"aixm_airports",
"aixm_airspaces",
"aixm_airways",
"aixm_navaids",
"client",
"eurofirs",
"navaids",
"nm_airspaces",
"nm_airways",
"nm_freeroute",
"nm_navaids",
"eurofirs",
"opensky",
"client",
"AllFT",
"Navaids",
"runways",
]

aircraft: "Aircraft"
Expand Down
2 changes: 1 addition & 1 deletion src/traffic/visualize/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import numpy as np

__all__ = ["rotate_marker", "atc_tower", "aircraft"]
__all__ = ["aircraft", "atc_tower", "rotate_marker"]


def rotate_marker(path: Path, degrees: float) -> Path:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cpa.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_cpa() -> None:
lateral_separation=10 * 1852,
vertical_separation=2000,
projection=CH1903p(),
round_t="10T",
round_t="10 min",
)

assert cpa is not None
Expand Down
24 changes: 13 additions & 11 deletions tests/test_flight.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,14 @@ def test_subtract() -> None:
assert sum(1 for _ in flight.holding_pattern()) == 1
hp = flight.next("holding_pattern")
assert hp is not None
assert pd.Timedelta("9T") < hp.duration < pd.Timedelta("11T")
assert pd.Timedelta("9 min") < hp.duration < pd.Timedelta("11 min")

without_hp = flight - hp
assert sum(1 for _ in without_hp) == 2
total_duration = sum(
(segment.duration for segment in without_hp), hp.duration
)
assert flight.duration - pd.Timedelta("1T") <= total_duration
assert flight.duration - pd.Timedelta("1 min") <= total_duration
assert total_duration <= flight.duration


Expand All @@ -126,7 +126,7 @@ def test_time_methods() -> None:
assert f"{first10.stop}" == "2018-05-30 15:31:37+00:00"
assert f"{last10.start}" == "2018-05-30 20:12:57+00:00"

first10 = flight.first("10T")
first10 = flight.first("10 min")
last10 = flight.last("10 minutes")
assert first10 is not None
assert last10 is not None
Expand Down Expand Up @@ -163,7 +163,7 @@ def test_time_methods() -> None:

low = flight.query("altitude < 100")
assert low is not None
shorter = low.split("10T").max()
shorter = low.split("10 min").max()
assert shorter is not None
assert shorter.duration < pd.Timedelta("6 minutes")

Expand Down Expand Up @@ -191,7 +191,7 @@ def test_bearing() -> None:
assert (
sum(
1
for chunk in subset.split("1T")
for chunk in subset.split("1 min")
if chunk.duration > pd.Timedelta("5 minutes")
)
== 7
Expand Down Expand Up @@ -608,7 +608,7 @@ def test_agg_time() -> None:
assert agg.max("altitude_max") <= agg.max("altitude")

app = flight.resample("30s").apply_time(
freq="30T",
freq="30 min",
factor=lambda f: f.distance() / f.cumulative_distance().max("cumdist"),
)
assert app.min("factor") < 1 / 15
Expand All @@ -619,7 +619,7 @@ def test_forward() -> None:

subset = flight.query("altitude < 300")
assert subset is not None
takeoff = subset.split("10T").next()
takeoff = subset.split("10 min").next()
assert takeoff is not None
forward = takeoff.forward(minutes=1)

Expand All @@ -633,7 +633,7 @@ def test_forward() -> None:
def test_cumulative_distance() -> None:
# https://github.com/xoolive/traffic/issues/61

first = belevingsvlucht.first("30T")
first = belevingsvlucht.first("30 min")
assert first is not None
f1 = first.cumulative_distance()
f2 = first.cumulative_distance(reverse=True)
Expand Down Expand Up @@ -676,18 +676,20 @@ def test_cumulative_distance() -> None:
def test_agg_time_colnames() -> None:
# https://github.com/xoolive/traffic/issues/66

cols = belevingsvlucht.agg_time("5T", altitude=("max", "mean")).data.columns
cols = belevingsvlucht.agg_time(
"5 min", altitude=("max", "mean")
).data.columns
assert list(cols)[-3:] == ["rounded", "altitude_max", "altitude_mean"]

cols = belevingsvlucht.agg_time(
"5T", altitude=lambda x: x.sum()
"5 min", altitude=lambda x: x.sum()
).data.columns
assert list(cols)[-3:] == ["altitude", "rounded", "altitude_<lambda>"]

def shh(x: Any) -> Any:
return x.sum()

cols = belevingsvlucht.agg_time("5T", altitude=shh).data.columns
cols = belevingsvlucht.agg_time("5 min", altitude=shh).data.columns
assert list(cols)[-2:] == ["rounded", "altitude_shh"]


Expand Down
2 changes: 1 addition & 1 deletion tests/test_intervals.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pandas as pd
from traffic.core.intervals import Interval, IntervalCollection

dates = pd.date_range("2022-03-21 11:10", "2022-03-21 11:20", freq="1T")
dates = pd.date_range("2022-03-21 11:10", "2022-03-21 11:20", freq="1 min")
h0, h1, h2, h3, h4, h5, h6, h7, h8, *_ = dates

i1 = Interval(h0, h2)
Expand Down

0 comments on commit bf198dc

Please sign in to comment.