Skip to content

Commit

Permalink
BUG: Fix passing unit-less level values to PlotObs. (Fixes #1474)
Browse files Browse the repository at this point in the history
  • Loading branch information
dopplershift committed Oct 2, 2020
1 parent 1fa4f3a commit 3a7408d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/metpy/plots/declarative.py
Original file line number Diff line number Diff line change
Expand Up @@ -1463,7 +1463,11 @@ def obsdata(self):

# Subset for a particular level if given
if self.level is not None:
data = data[data.pressure == self.level.m]
try:
mag = self.level.magnitude
except AttributeError:
mag = self.level
data = data[data.pressure == mag]

# Subset for our particular time
if self.time is not None:
Expand Down
13 changes: 13 additions & 0 deletions tests/plots/test_declarative.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,19 @@ def test_plotobs_subset_level(sample_obs):
pd.testing.assert_frame_equal(obs.obsdata, truth)


def test_plotobs_subset_level_no_units(sample_obs):
"""Test PlotObs subsetting based on level."""
obs = PlotObs()
obs.data = sample_obs
obs.level = 1000

truth = pd.DataFrame([('2020-08-06 13:00', 'KDEN', 1000, 5, 13),
('2020-08-06 12:59', 'KOKC', 1000, 6, 14)],
columns=['time', 'stid', 'pressure', 'temperature', 'dewpoint'],
index=[4, 5])
pd.testing.assert_frame_equal(obs.obsdata, truth)


def test_plotobs_subset_time(sample_obs):
"""Test PlotObs subsetting for a particular time."""
obs = PlotObs()
Expand Down

0 comments on commit 3a7408d

Please sign in to comment.