Skip to content

Commit 639a31a

Browse files
committed
ENH: Clean up gust time handling for NDBC cwind
This eliminates a warning with Pandas 3.
1 parent 71afec7 commit 639a31a

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

src/siphon/simplewebservice/ndbc.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,11 @@ def _parse_cwind(content):
187187
df['gust_direction'] = df['gust_direction'].replace(999, np.nan)
188188
df['wind_gust'] = df['wind_gust'].replace(99.0, np.nan)
189189
df['time'] = pd.to_datetime(df[['year', 'month', 'day', 'hour', 'minute']], utc=True)
190-
df['hours'] = np.floor(df['gust_time'] / 100)
190+
df['hours'] = df['gust_time'] // 100
191191
df['minutes'] = df['gust_time'] - df['hours'] * 100
192-
df['hours'] = df['hours'].replace(99, np.nan)
193-
df['minutes'] = df['minutes'].replace(99, np.nan)
194192
df['gust_time'] = pd.to_datetime(df[['year', 'month', 'day', 'hours', 'minutes']],
195193
utc=True)
194+
df['gust_time'] = df['gust_time'].where(df['hours'] != 99, pd.NaT)
196195
df = df.drop(columns=['year', 'month', 'day', 'hour', 'minute',
197196
'hours', 'minutes'])
198197
with warnings.catch_warnings():

tests/test_ndbc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import numpy as np
99
from numpy.testing import assert_almost_equal, assert_equal
10+
import pandas as pd
1011
import pytest
1112

1213
from siphon.http_util import utc
@@ -93,6 +94,7 @@ def test_ndbc_realtime_cwind():
9394
assert_almost_equal(df['wind_gust'][0], 9.0, 1)
9495
assert df['gust_time'][0] == datetime(2018, 8, 1, 14, 49, 0, tzinfo=utc)
9596
assert df['time'][0] == datetime(2018, 8, 1, 14, 50, 0, tzinfo=utc)
97+
assert pd.isna(df['gust_time'][1])
9698

9799
assert df.units['wind_direction'] == 'degrees'
98100
assert df.units['wind_speed'] == 'meters/second'

0 commit comments

Comments
 (0)