Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code scanning #1934

Merged
merged 5 commits into from Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions .codeclimate.yml
Expand Up @@ -40,8 +40,7 @@ plugins:

exclude_patterns:
- "src/metpy/io/_nexrad_msgs/msg*.py"
- "src/metpy/io/metar_parse.peg"
- "src/metpy/io/metar_parser.py"
- "src/metpy/io/_metar_parser/*"
- "docs/**/*"
- "staticdata/**/*"
- "tests/*/baseline/*"
Expand Down
2 changes: 1 addition & 1 deletion .github/codeql/codeql-config.yml
Expand Up @@ -4,6 +4,6 @@ queries:
- uses: security-and-quality

paths-ignore:
- src/metpy/io/metar_parser.py
- src/metpy/io/_metar_parser
- tutorials
- examples
5 changes: 5 additions & 0 deletions .github/workflows/code-analysis.yml
Expand Up @@ -6,6 +6,11 @@ on:
pull_request:
# The branches below must be a subset of the branches above
branches: [main]
paths:
- '**.py'
- '.github/codeql/**'
- '.github/workflows/code-analysis.yml'

schedule:
- cron: '0 8 * * 6'

Expand Down
2 changes: 1 addition & 1 deletion .lgtm.yml
@@ -1,6 +1,6 @@
path_classifiers:
generated:
- src/metpy/io/metar_parser.py
- src/metpy/io/_metar_parser/metar_parser.py
library:
- src/metpy/deprecation.py
test:
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Expand Up @@ -79,7 +79,7 @@ multiline-quotes = double
rst-roles = class, data, doc, func, meth, mod
rst-directives = plot, versionchanged
docstring-convention = numpy
exclude = docs build src/metpy/io/metar_parser.py
exclude = docs build src/metpy/io/_metar_parser/metar_parser.py
select = A B C D E F G H I J K L M N O P Q R S T U V W X Y Z B902
ignore = F405 W503 RST902 SIM106
per-file-ignores = examples/*.py: D MPY001 T003 T001
Expand Down
1,093 changes: 549 additions & 544 deletions src/metpy/io/metar_parser.py → src/metpy/io/_metar_parser/metar_parser.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/metpy/io/metar.py
Expand Up @@ -10,8 +10,8 @@
import numpy as np
import pandas as pd

from ._metar_parser.metar_parser import parse, ParseError
from ._tools import open_as_needed
from .metar_parser import parse, ParseError
from .station_data import station_info
from ..package_tools import Exporter
from ..units import units
Expand Down
8 changes: 5 additions & 3 deletions src/metpy/io/nexrad.py
Expand Up @@ -11,7 +11,6 @@
import pathlib
import re
import struct
from struct import Struct
from xdrlib import Unpacker

import numpy as np
Expand Down Expand Up @@ -451,7 +450,7 @@ def _decode_msg5(self, msg_hdr):
def _decode_msg13(self, msg_hdr):
data = self._buffer_segment(msg_hdr)
if data:
data = Struct(f'>{len(data) // 2:d}h').unpack(data)
data = struct.Struct(f'>{len(data) // 2:d}h').unpack(data)
# Legacy format doesn't have date/time and has fewer azimuths
if data[0] <= 5:
num_el = data[0]
Expand Down Expand Up @@ -494,7 +493,7 @@ def _decode_msg15(self, msg_hdr):
# will be returned concatenated when this is the case
data = self._buffer_segment(msg_hdr)
if data:
date, time, num_el, *data = Struct(f'>{len(data) // 2:d}h').unpack(data)
date, time, num_el, *data = struct.Struct(f'>{len(data) // 2:d}h').unpack(data)
if num_el == 0:
log.info('Message 15 num_el is 0--likely legacy clutter filter notch width. '
'Skipping...')
Expand Down Expand Up @@ -665,6 +664,8 @@ def _buffer_segment(self, msg_hdr):
if msg_hdr.num_segments == len(bufs):
self._msg_buf.pop(msg_hdr.msg_type)
return b''.join(bytes(item[1]) for item in sorted(bufs.items()))
else:
return None

def _add_sweep(self, hdr):
if not self.sweeps and not hdr.rad_status & START_VOLUME:
Expand Down Expand Up @@ -1754,6 +1755,7 @@ def __init__(self, filename):
self._buffer.splice(comp_start, decomp_data)
assert self._buffer.check_remains(self.metadata['uncompressed_size'])
except OSError:
# Compression didn't work, so we just assume it wasn't actually compressed.
pass

# Unpack the various blocks, if present. The factor of 2 converts from
Expand Down
2 changes: 0 additions & 2 deletions src/metpy/pandas.py
Expand Up @@ -3,12 +3,10 @@
# SPDX-License-Identifier: BSD-3-Clause
"""Provide accessors to enhance interoperability between Pandas and MetPy."""
import functools
import logging

import pandas as pd

__all__ = []
log = logging.getLogger(__name__)


def preprocess_pandas(func):
Expand Down
4 changes: 2 additions & 2 deletions src/metpy/plots/cartopy_utils.py
Expand Up @@ -75,6 +75,6 @@ def import_cartopy():
class CartopyStub:
"""Fail if a CartoPy attribute is accessed."""

def __getattr__(self, item):
def __getattr__(self, name):
"""Raise an error on any attribute access."""
raise RuntimeError(f'CartoPy is required to use this feature ({item}).')
raise AttributeError(f'Cannot use {name} without Cartopy installed.')
1 change: 1 addition & 0 deletions src/metpy/plots/wx_symbols.py
Expand Up @@ -63,6 +63,7 @@ def wx_code_to_numeric(codes):
wx_sym_list.append(wx_code_map[wxcode[opt]])
break
except KeyError:
# That option didn't work--move on.
pass
else:
wx_sym_list.append(0)
Expand Down
35 changes: 0 additions & 35 deletions tests/calc/test_basic.py
Expand Up @@ -317,41 +317,6 @@ def test_geopotential_to_height_32bit():
assert_almost_equal(geopotential_to_height(geopot), truth, 2)


# class TestIrrad(object):
# def test_basic(self):
# 'Test the basic solar irradiance calculation.'
# from datetime import date

# d = date(2008, 9, 28)
# lat = 35.25
# hours = np.linspace(6,18,10)

# s = solar_irradiance(lat, d, hours)
# values = np.array([0., 344.1, 682.6, 933.9, 1067.6, 1067.6, 933.9,
# 682.6, 344.1, 0.])
# assert_array_almost_equal(s, values, 1)

# def test_scalar(self):
# from datetime import date
# d = date(2008, 9, 28)
# lat = 35.25
# hour = 9.5
# s = solar_irradiance(lat, d, hour)
# assert_almost_equal(s, 852.1, 1)

# def test_invalid(self):
# 'Test for values that should be masked.'
# from datetime import date
# d = date(2008, 9, 28)
# lat = 35.25
# hours = np.linspace(0,22,12)
# s = solar_irradiance(lat, d, hours)

# mask = np.array([ True, True, True, True, False, False, False,
# False, False, True, True, True])
# assert_array_equal(s.mask, mask)


def test_pressure_to_heights_basic():
"""Test basic pressure to height calculation for standard atmosphere."""
pressures = np.array([975.2, 987.5, 956., 943.]) * units.mbar
Expand Down
2 changes: 1 addition & 1 deletion tests/plots/test_cartopy_utils.py
Expand Up @@ -80,7 +80,7 @@ def test_cartopy_stub(monkeypatch):
monkeypatch.setitem(sys.modules, 'cartopy.crs', None)

ccrs = cartopy_utils.import_cartopy()
with pytest.raises(RuntimeError, match='CartoPy is required'):
with pytest.raises(AttributeError, match='without Cartopy'):
ccrs.PlateCarree()


Expand Down
4 changes: 2 additions & 2 deletions tests/test_xarray.py
Expand Up @@ -1069,8 +1069,8 @@ def test_update_attribute_dictionary(test_ds_generic):
def test_update_attribute_callable(test_ds_generic):
"""Test update_attribute using callable."""
def even_ascii(varname, **kwargs):
if ord(varname[0]) % 2 == 0:
return 'yes'
return 'yes' if ord(varname[0]) % 2 == 0 else None

result = test_ds_generic.metpy.update_attribute('even', even_ascii)

# Test attribute updates
Expand Down