[Git][debian-gis-team/fiona][upstream] New upstream version 1.7.13

Bas Couwenberg gitlab at salsa.debian.org
Wed Aug 15 18:41:07 BST 2018


Bas Couwenberg pushed to branch upstream at Debian GIS Project / fiona


Commits:
77c7d467 by Bas Couwenberg at 2018-08-15T16:19:04Z
New upstream version 1.7.13
- - - - -


9 changed files:

- .travis.yml
- CHANGES.txt
- fiona/__init__.py
- + fiona/isfieldnull1.pxi
- + fiona/isfieldnull22.pxi
- fiona/ogrext2.pyx
- requirements-dev.txt
- setup.py
- tests/test_feature.py


Changes:

=====================================
.travis.yml
=====================================
--- a/.travis.yml
+++ b/.travis.yml
@@ -14,6 +14,7 @@ env:
     - GDALVERSION="1.11.5"
     - GDALVERSION="2.0.3"
     - GDALVERSION="2.1.4"
+    - GDALVERSION="2.2.4"
 addons:
   apt:
     packages:


=====================================
CHANGES.txt
=====================================
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -3,6 +3,14 @@ Changes
 
 All issue numbers are relative to https://github.com/Toblerity/Fiona/issues.
 
+1.7.13 (2018-07-17)
+-------------------
+
+In GDAL 2.2, the behavior of GDAL with respect to null fields changed (#460).
+A fix in the master (1.8-to-be) branch has been back-ported so that Fiona's
+results with GDAL 2.1 and 2.2 are the same. The value reported for unset
+integer or string fields will be `None` and not `0` or `""`.
+
 1.7.12 (2018-06-11)
 -------------------
 


=====================================
fiona/__init__.py
=====================================
--- a/fiona/__init__.py
+++ b/fiona/__init__.py
@@ -81,7 +81,7 @@ import uuid
 
 
 __all__ = ['bounds', 'listlayers', 'open', 'prop_type', 'prop_width']
-__version__ = "1.7.12"
+__version__ = "1.7.13"
 __gdal_version__ = get_gdal_release_name().decode('utf-8')
 
 log = logging.getLogger(__name__)


=====================================
fiona/isfieldnull1.pxi
=====================================
--- /dev/null
+++ b/fiona/isfieldnull1.pxi
@@ -0,0 +1,12 @@
+
+cdef extern from "ogr_api.h":
+
+    int OGR_F_IsFieldSet (void *feature, int n)
+
+
+cdef bint is_field_null(void *feature, int n):
+    if not OGR_F_IsFieldSet(feature, n):
+        return True
+    else:
+        return False
+


=====================================
fiona/isfieldnull22.pxi
=====================================
--- /dev/null
+++ b/fiona/isfieldnull22.pxi
@@ -0,0 +1,14 @@
+
+cdef extern from "ogr_api.h":
+
+    int OGR_F_IsFieldSet (void *feature, int n)
+    int OGR_F_IsFieldNull(void *feature, int n)
+
+
+cdef bint is_field_null(void *feature, int n):
+    if OGR_F_IsFieldNull(feature, n):
+        return True
+    elif not OGR_F_IsFieldSet(feature, n):
+        return True
+    else:
+        return False


=====================================
fiona/ogrext2.pyx
=====================================
--- a/fiona/ogrext2.pyx
+++ b/fiona/ogrext2.pyx
@@ -34,6 +34,10 @@ from libc.string cimport strcmp
 
 
 log = logging.getLogger("Fiona")
+class NullHandler(logging.Handler):
+    def emit(self, record):
+        pass
+log.addHandler(NullHandler())
 
 # Mapping of OGR integer field types to Fiona field type names.
 #
@@ -122,19 +126,25 @@ def _bounds(geometry):
     except (KeyError, TypeError):
         return None
 
+
 def calc_gdal_version_num(maj, min, rev):
     """Calculates the internal gdal version number based on major, minor and revision"""
     return int(maj * 1000000 + min * 10000 + rev*100)
 
+
 def get_gdal_version_num():
     """Return current internal version number of gdal"""
     return int(ogrext2.GDALVersionInfo("VERSION_NUM"))
 
+
 def get_gdal_release_name():
     """Return release name of gdal"""
     return ogrext2.GDALVersionInfo("RELEASE_NAME")
 
 
+include "isfieldnull.pxi"
+
+
 # Feature extension classes and functions follow.
 
 cdef class FeatureBuilder:
@@ -157,6 +167,7 @@ cdef class FeatureBuilder:
         cdef int tz = 0
         cdef int retval
         cdef const char *key_c = NULL
+        cdef bint is_null
         props = OrderedDict()
         for i in range(ogrext2.OGR_F_GetFieldCount(feature)):
             fdefn = ogrext2.OGR_F_GetFieldDefnRef(feature, i)
@@ -177,8 +188,10 @@ cdef class FeatureBuilder:
 
             # TODO: other types
             fieldtype = FIELD_TYPES_MAP[fieldtypename]
-            if not ogrext2.OGR_F_IsFieldSet(feature, i):
+
+            if is_field_null(feature, i):
                 props[key] = None
+
             elif fieldtype is int:
                 props[key] = ogrext2.OGR_F_GetFieldAsInteger64(feature, i)
             elif fieldtype is float:


=====================================
requirements-dev.txt
=====================================
--- a/requirements-dev.txt
+++ b/requirements-dev.txt
@@ -1,6 +1,6 @@
 -r requirements.txt
 coverage
-cython>=0.21.2
+cython==0.28.4
 nose
 pytest
 pytest-cov


=====================================
setup.py
=====================================
--- a/setup.py
+++ b/setup.py
@@ -1,6 +1,5 @@
 from distutils.command.sdist import sdist
 from distutils import log
-import logging
 import os
 import shutil
 import subprocess
@@ -168,11 +167,19 @@ if 'clean' not in sys.argv:
             log.info("Copying proj data from %s" % projdatadir)
             copy_data_tree(projdatadir, 'fiona/proj_data')
 
+
+def calc_gdal_version_num(maj=1, min=0, rev=0):
+    return int(maj * 1000000 + min * 10000 + rev*100)
+
+
+GDAL_VERSION_NUM = calc_gdal_version_num(*[int(i) for i in gdalversion.split(".")])
+
 ext_options = dict(
     include_dirs=include_dirs,
     library_dirs=library_dirs,
     libraries=libraries,
-    extra_link_args=extra_link_args)
+    extra_link_args=extra_link_args,
+)
 
 # Define the extension modules.
 ext_modules = []
@@ -192,13 +199,20 @@ if source_is_repo and "clean" not in sys.argv:
         log.info("Building Fiona for gdal 2.x: {0}".format(gdalversion))
         shutil.copy('fiona/ogrext2.pyx', 'fiona/ogrext.pyx')
 
+    # Add shim for OGR_IsFieldNull.
+    if gdalversion.startswith("2.2"):
+        shutil.copy("fiona/isfieldnull22.pxi", "fiona/isfieldnull.pxi")
+    else:
+        shutil.copy("fiona/isfieldnull1.pxi", "fiona/isfieldnull.pxi")
+
     ext_modules = cythonize([
         Extension('fiona._geometry', ['fiona/_geometry.pyx'], **ext_options),
         Extension('fiona._transform', ['fiona/_transform.pyx'], **ext_options),
         Extension('fiona._crs', ['fiona/_crs.pyx'], **ext_options),
         Extension('fiona._drivers', ['fiona/_drivers.pyx'], **ext_options),
         Extension('fiona._err', ['fiona/_err.pyx'], **ext_options),
-        Extension('fiona.ogrext', ['fiona/ogrext.pyx'], **ext_options)])
+        Extension('fiona.ogrext', ['fiona/ogrext.pyx'], **ext_options)],
+        compile_time_env={"GDAL_VERSION_NUM": GDAL_VERSION_NUM},)
 
 # If there's no manifest template, as in an sdist, we just specify .c files.
 elif "clean" not in sys.argv:


=====================================
tests/test_feature.py
=====================================
--- a/tests/test_feature.py
+++ b/tests/test_feature.py
@@ -1,17 +1,14 @@
 # testing features, to be called by nosetests
 
-import logging
 import os
 import shutil
-import sys
 import tempfile
 import unittest
 
-from fiona import collection
+import fiona
 from fiona.collection import Collection
 from fiona.ogrext import featureRT
 
-#logging.basicConfig(stream=sys.stderr, level=logging.INFO)
 
 class PointRoundTripTest(unittest.TestCase):
     def setUp(self):
@@ -110,3 +107,27 @@ class PolygonRoundTripTest(unittest.TestCase):
         g = featureRT(f, self.c)
         self.assertEqual(g['properties']['title'], 'foo')
 
+
+class NullFieldTest(unittest.TestCase):
+    """See issue #460."""
+
+    def setUp(self):
+        self.tempdir = tempfile.mkdtemp()
+
+    def tearDown(self):
+        shutil.rmtree(self.tempdir)
+
+    def test_feature_null_field(self):
+        """Undefined int feature properties are None, not 0"""
+
+        meta = {"driver": "ESRI Shapefile", "schema": {"geometry": "Point", "properties": {"RETURN_P": "int"}}}
+        filename = os.path.join(self.tempdir, "test_null.shp")
+
+        with fiona.open(filename, "w", **meta) as dst:
+            g = {"coordinates": [1.0, 2.0], "type": "Point"}
+            feature = {"geometry": g, "properties": {"RETURN_P": None}}
+            dst.write(feature)
+
+        with fiona.open(filename, "r") as src:
+            feature = next(iter(src))
+            self.assertEqual(feature["properties"]["RETURN_P"], None)



View it on GitLab: https://salsa.debian.org/debian-gis-team/fiona/commit/77c7d467c27924f56e24b3bc1da1322e195b5131

-- 
View it on GitLab: https://salsa.debian.org/debian-gis-team/fiona/commit/77c7d467c27924f56e24b3bc1da1322e195b5131
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-grass-devel/attachments/20180815/b1b79c99/attachment-0001.html>


More information about the Pkg-grass-devel mailing list