Skip to content

Commit

Permalink
Merge pull request #1414 from girder/band-nans
Browse files Browse the repository at this point in the history
Remove NaN values from band information for JSON serializability
  • Loading branch information
annehaley authored Dec 20, 2023
2 parents a734a0b + ad70cac commit e1373b8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion sources/gdal/large_image_source_gdal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,13 @@ def getBandInformation(self, statistics=True, dataset=None, **kwargs):
if band.GetMaskBand():
info['maskband'] = band.GetMaskBand().GetBand() or None
# Only keep values that aren't None or the empty string
infoSet[i + 1] = {k: v for k, v in info.items() if v not in (None, '')}
infoSet[i + 1] = {
k: v for k, v in info.items()
if v not in (None, '') and not (
isinstance(v, float) and
math.isnan(v)
)
}
if not cache:
return infoSet
self._bandInfo = infoSet
Expand Down
8 changes: 7 additions & 1 deletion sources/rasterio/large_image_source_rasterio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,13 @@ def getBandInformation(self, statistics=True, dataset=None, **kwargs):
# info["maskband"] = dataset.mask_flag_enums[i - 1][1].value

# Only keep values that aren't None or the empty string
infoSet[i] = {k: v for k, v in info.items() if v not in (None, '')}
infoSet[i] = {
k: v for k, v in info.items()
if v not in (None, '') and not (
isinstance(v, float) and
math.isnan(v)
)
}

# set the value to cache if needed
if cache:
Expand Down

0 comments on commit e1373b8

Please sign in to comment.