Skip to content

Commit

Permalink
fix exception catch and test
Browse files Browse the repository at this point in the history
  • Loading branch information
kgoebber committed Jan 11, 2020
1 parent a276ec4 commit a2743b6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/metpy/io/station_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def add_station_lat_lon(df, stn_var):
info = station_info[stn]
df.loc[df[stn_var] == stn, 'latitude'] = info.latitude
df.loc[df[stn_var] == stn, 'longitude'] = info.longitude
except AttributeError:
except KeyError:
df.loc[df[stn_var] == stn, 'latitude'] = np.nan
df.loc[df[stn_var] == stn, 'longitude'] = np.nan
return df
18 changes: 9 additions & 9 deletions tests/io/test_station_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

def test_add_lat_lon_station_data():
"""Test for when the METAR does not correspond to a station in the dictionary."""
df = pd.DataFrame({'station': ['KOUN', 'KVPZ', 'KDEN', 'KAAA']})
df = pd.DataFrame({'station': ['KOUN', 'KVPZ', 'KDEN', 'PAAA']})

df = add_station_lat_lon(df, 'station')
assert_almost_equal(df.loc[df.station == 'KOUN'].latitude.values, 35.25)
assert_almost_equal(df.loc[df.station == 'KOUN'].longitude.values, -97.47)
assert_almost_equal(df.loc[df.station == 'KVPZ'].latitude.values, 41.45)
assert_almost_equal(df.loc[df.station == 'KVPZ'].longitude.values, -87)
assert_almost_equal(df.loc[df.station == 'KDEN'].latitude.values, 39.85)
assert_almost_equal(df.loc[df.station == 'KDEN'].longitude.values, -104.65)
assert_almost_equal(df.loc[df.station == 'PAAA'].longitude.values, np.nan)
assert_almost_equal(df.loc[df.station == 'PAAA'].longitude.values, np.nan)
assert_almost_equal(df.loc[df.station == 'KOUN'].latitude.values[0], 35.25)
assert_almost_equal(df.loc[df.station == 'KOUN'].longitude.values[0], -97.47)
assert_almost_equal(df.loc[df.station == 'KVPZ'].latitude.values[0], 41.45)
assert_almost_equal(df.loc[df.station == 'KVPZ'].longitude.values[0], -87)
assert_almost_equal(df.loc[df.station == 'KDEN'].latitude.values[0], 39.85)
assert_almost_equal(df.loc[df.station == 'KDEN'].longitude.values[0], -104.65)
assert_almost_equal(df.loc[df.station == 'PAAA'].latitude.values[0], np.nan)
assert_almost_equal(df.loc[df.station == 'PAAA'].longitude.values[0], np.nan)

0 comments on commit a2743b6

Please sign in to comment.