diff --git a/requirements.txt b/requirements.txt index bba9eeb..ad82f14 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,3 +3,4 @@ numpy>=1.9 rasterio>=0.27 cligj>=0.4 fiona +simplejson diff --git a/src/rasterstats/cli.py b/src/rasterstats/cli.py index cd85e68..d365439 100644 --- a/src/rasterstats/cli.py +++ b/src/rasterstats/cli.py @@ -3,13 +3,9 @@ from __future__ import division import logging -try: - import simplejson as json -except: - import json - import click import cligj +import simplejson as json from rasterstats import gen_zonal_stats, gen_point_query from rasterstats._version import __version__ as version diff --git a/src/rasterstats/io.py b/src/rasterstats/io.py index e1529ea..8138655 100644 --- a/src/rasterstats/io.py +++ b/src/rasterstats/io.py @@ -20,9 +20,9 @@ PY3 = sys.version_info[0] >= 3 if PY3: - string_types = str, + string_types = str, # pragma: no cover else: - string_types = basestring, + string_types = basestring, # pragma: no cover def wrap_geom(geom): """ Wraps a geometry dict in an GeoJSON Feature diff --git a/src/rasterstats/main.py b/src/rasterstats/main.py index 96b6700..247f63f 100644 --- a/src/rasterstats/main.py +++ b/src/rasterstats/main.py @@ -125,12 +125,6 @@ def gen_zonal_stats( if not affine: affine = Affine.from_gdal(*transform) - ndv = kwargs.get('nodata_value') - if ndv: - warnings.warn("Use `nodata` instead of `nodata_value`", DeprecationWarning) - if not nodata: - nodata = ndv - cp = kwargs.get('copy_properties') if cp: warnings.warn("Use `geojson_out` to preserve feature properties", diff --git a/src/rasterstats/utils.py b/src/rasterstats/utils.py index d5d529e..9987789 100644 --- a/src/rasterstats/utils.py +++ b/src/rasterstats/utils.py @@ -12,6 +12,7 @@ ['sum', 'std', 'median', 'majority', 'minority', 'unique', 'range', 'nodata'] # also percentile_{q} but that is handled as special case + def get_percentile(stat): if not stat.startswith('percentile_'): raise ValueError("must start with 'percentile_'") @@ -50,9 +51,10 @@ def rasterize_geom(geom, like, all_touched=False): def stats_to_csv(stats): if sys.version_info[0] >= 3: - from io import StringIO as IO + from io import StringIO as IO # pragma: no cover else: - from cStringIO import StringIO as IO + from cStringIO import StringIO as IO # pragma: no cover + import csv csv_fh = IO() diff --git a/tests/test_utils.py b/tests/test_utils.py index 5431b15..a6edc06 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,7 +1,9 @@ import sys import os import pytest -from rasterstats.utils import stats_to_csv, get_percentile, remap_categories +from shapely.geometry import LineString +from rasterstats.utils import \ + stats_to_csv, get_percentile, remap_categories, boxify_points from rasterstats import zonal_stats from rasterstats.utils import VALID_STATS @@ -31,6 +33,13 @@ def test_get_percentile(): assert get_percentile('percentile_100') == 100.0 assert get_percentile('percentile_13.2') == 13.2 +def test_get_bad_percentile(): + with pytest.raises(ValueError): + get_percentile('foo') + + with pytest.raises(ValueError): + get_percentile('percentile_101') + with pytest.raises(ValueError): get_percentile('percentile_101') @@ -48,3 +57,9 @@ def test_remap_categories(): assert 1 not in new_stats.keys() assert 'grassland' in new_stats.keys() assert 3 in new_stats.keys() + + +def test_boxify_non_point(): + line = LineString([(0, 0), (1, 1)]) + with pytest.raises(ValueError): + boxify_points(line, None)