diff --git a/src/traffic/algorithms/openap.py b/src/traffic/algorithms/openap.py index 88a0363a..9b9e990a 100644 --- a/src/traffic/algorithms/openap.py +++ b/src/traffic/algorithms/openap.py @@ -32,8 +32,7 @@ def phases(self, twindow: int = 60) -> "Flight": fp = FlightPhase() fp.set_trajectory( - (self.data.timestamp.values - np.datetime64("1970-01-01")) - / np.timedelta64(1, "s"), + (self.data.timestamp.astype(int) // 1_000_000_000).values, altitude, groundspeed, vertical_rate, diff --git a/src/traffic/core/flight.py b/src/traffic/core/flight.py index d705968f..5d301fed 100644 --- a/src/traffic/core/flight.py +++ b/src/traffic/core/flight.py @@ -116,17 +116,17 @@ def _split( # This method helps splitting a flight into several. if data.shape[0] < 2: return - diff = data.timestamp.diff().values + diff = data.timestamp.diff() if unit is None: delta = pd.Timedelta(value).to_timedelta64() else: delta = np.timedelta64(value, unit) # There seems to be a change with numpy >= 1.18 # max() now may return NaN, therefore the following fix - max_ = np.nanmax(diff) + max_ = diff.max() if max_ > delta: # np.nanargmax seems bugged with timestamps - argmax = np.where(diff == max_)[0][0] + argmax = diff.argmax() yield from _split(data.iloc[:argmax], value, unit) yield from _split(data.iloc[argmax:], value, unit) else: @@ -1490,7 +1490,7 @@ def split( - in the NumPy style: ``Flight.split(10, 'm')`` (see ``np.timedelta64``); - - in the pandas style: ``Flight.split('10T')`` (see ``pd.Timedelta``) + - in the pandas style: ``Flight.split('10 min')`` (see ``pd.Timedelta``) If the `condition` parameter is set, the flight is split between two segments only if `condition(f1, f2)` is verified. diff --git a/src/traffic/core/time.py b/src/traffic/core/time.py index 3a730c71..c4e06530 100644 --- a/src/traffic/core/time.py +++ b/src/traffic/core/time.py @@ -24,7 +24,7 @@ _log = logging.getLogger(__name__) -def to_datetime(time: timelike) -> datetime: +def to_datetime(time: timelike) -> pd.Timestamp: """Facility to convert anything to a datetime. This function will soon be replaced by pd.to_datetime. @@ -41,10 +41,10 @@ def to_datetime(time: timelike) -> datetime: if isinstance(time, str): time = pd.Timestamp(time, tz="utc") - if isinstance(time, pd.Timestamp): - time = time.to_pydatetime() + if isinstance(time, datetime): + time = pd.Timestamp(time) if isinstance(time, Real): - time = datetime.fromtimestamp(float(time), timezone.utc) + time = pd.Timestamp(float(time), tz="utc", unit="s") if time.tzinfo is None: # coverage: ignore _log.warning( "This timestamp is tz-naive. Things may not work as expected. " diff --git a/src/traffic/data/adsb/opensky.py b/src/traffic/data/adsb/opensky.py index 3c0d2a9d..87ceb03a 100644 --- a/src/traffic/data/adsb/opensky.py +++ b/src/traffic/data/adsb/opensky.py @@ -150,11 +150,6 @@ def format_history( if column_name in df.columns: df[column_name] = df[column_name].astype(float) - if "onground" in df.columns and df.onground.dtype != bool: - df.onground = df.onground == "true" - df.alert = df.alert == "true" - df.spi = df.spi == "true" - # better (to me) formalism about columns df = df.rename( columns={