<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<font face="Verdana">Thank you. I can help you repro it if you want
to take a look.<br>
<br>
I'm having trouble attaching a .img file to email. My email system
doesn't want to allow it, even if I put it in a zip. But h</font><font face="Verdana">ere is a simple way to repro it by creating the
file with GDAL itself. </font><font face="Verdana">(In this
example, I used float64 and the same warning occurs.) </font><font face="Verdana">You could use this to produce a test file. If you'd
prefer I send a file I can post it to a file exchange service.<br>
<br>
>>> import numpy as np<br>
>>><br>
>>> from osgeo import gdal<br>
>>> print(gdal.__version__)<br>
3.9.2e<br>
>>> gdal.UseExceptions()<br>
>>><br>
>>> # Create the dataset as float64 with 1 band<br>
>>> f = 'has_nans.img'<br>
>>> drv = gdal.GetDriverByName('HFA')<br>
>>> ds = drv.Create(f, 100, 100, 1, gdal.GDT_Float64)<br>
>>><br>
>>> # Make some fake data; set some cells to nan,
although this is not necessary to repro the warning<br>
>>> data = np.arange(100*100,
dtype=float).reshape(100,100)<br>
>>> data[0:20,0:30] = float('nan')<br>
>>><br>
>>> # Write the data to the band<br>
>>> band = ds.GetRasterBand(1)<br>
>>> band.SetNoDataValue(float('nan'))<br>
0<br>
>>> band.WriteArray(data, 0, 0)<br>
0<br>
>>><br>
>>> # Close the dataset<br>
>>> del band, ds<br>
>>><br>
>>> # Open it again - warning happens here<br>
>>> ds = gdal.Open(f, gdal.GA_ReadOnly)<br>
Warning 1: NaN converted to INT_MAX.<br>
<br>
Jason<br>
</font><br>
<div class="moz-cite-prefix">On 5/8/25 18:39, Even Rouault wrote:<br>
</div>
<blockquote type="cite" cite="mid:196c2174-3430-4216-a3d4-4ac7a760b697@spatialys.com">
<p>There are metadata fields that the HFA driver opens. That must
come from that. Always shutting down the warning could be
inappropriate, but perhaps in the context where the warning is
emitted the driver could avoid emitting it. But we need to have
access to the file to better understand the call path.<br>
</p>
<div class="moz-cite-prefix">Le 09/05/2025 à 00:35, Jason Roberts
a écrit :<br>
</div>
<blockquote type="cite" cite="mid:8d468679-aad9-4d65-8f9f-62551b414e2e@duke.edu"> <font face="Verdana">Hi Even,<br>
<br>
Thanks. I can silence this with a custom error handler (I
tested it, and it works). But the part that is confusing to
me, as a user of the Python API, is that I did not ask the API
to do anything with int32s. All I did was open the dataset
using the default parameters of gdal.Open(). I would not
expect a warning to be reported in that circumstance, unless
opening .img files that use nan as the NoData value was
problematic for GDAL in some way. That is why I was suggesting
that the warning be removed.<br>
<br>
Jason<br>
</font><br>
<div class="moz-cite-prefix">On 5/8/25 17:51, Even Rouault
wrote:<br>
</div>
<blockquote type="cite" cite="mid:7f77f6f0-caea-4e70-9ed2-c3c8848bb00f@spatialys.com">
<p>Jason,</p>
<p>It looks like something in the code asks a float64 field to
be returned as a int32, and thus NaN has to be turned into
something else. That's perhaps fine in the context where
that happens with your file and could potentially be
silenced, but access to the file would be needed to
investigate</p>
<p>Even<br>
</p>
<div class="moz-cite-prefix">Le 08/05/2025 à 23:01, Jason
Roberts via gdal-dev a écrit :<br>
</div>
<blockquote type="cite" cite="mid:2d66b13b-34e6-460d-a687-90e0a4196eda@duke.edu"> <font face="Verdana">Hi GDAL team,<br>
<br>
I'm working with the GDAL Python API. I have some HFA
(.img) files that are float32 and that use nan as their
NoData value. As far as I can tell, using nan is allowed
but I could be wrong. When I open them, I get "Warning 1:
NaN converted to INT_MAX." Everything seems to work fine
after that. Is this message something I need to worry
about? If not, may I suggest you remove it from the HFA
driver if possible?<br>
<br>
Here's some code demonstrating the message. If need be, I
can provide an example file, or write some code to
generate one.<br>
<br>
>>> import numpy as np<br>
>>> from osgeo import gdal<br>
>>> gdal.__version__ # this version is
packaged with ArcGIS Pro 3.4, but I don't think the
version matters<br>
'3.9.2e'<br>
>>> ds =
gdal.Open(r'\\conch\denmod\Covariates\NARW25\CMEMS_GLORYS\SST\1999\SST_199901.img',
gdal.GA_ReadOnly)<br>
Warning 1: NaN converted to INT_MAX.<br>
>>> band = ds.GetRasterBand(1)<br>
</font><font face="Verdana">>>>
gdal.GetDataTypeName(band.DataType)<br>
'Float32'<br>
</font><font face="Verdana">>>>
band.GetNoDataValue()<br>
nan<br>
>>> arr = band.ReadAsArray() # the data look
ok:<br>
>>> np.isnan(arr).sum()<br>
86788<br>
>>> (~np.isnan(arr)).sum()<br>
142985<br>
</font><font face="Verdana">>>> np.max(arr)<br>
nan<br>
</font><font face="Verdana">>>> np.nanmax(arr)<br>
27.078554<br>
<br>
As far as I can tell, the warning comes from this code in
gdal/frmts/hfa/hfafield.cpp:<br>
<br>
else if (std::isnan(dfDoubleRet))<br>
{<br>
CPLError(CE_Warning, CPLE_AppDefined,<br>
"NaN converted to INT_MAX.");<br>
nIntRet = nMax;<br>
}<br>
<br>
But I don't know if there are any negative ramifications
that will result.<br>
<br>
Thank you for your help. And, as always, thank you very
much for developing and maintaining GDAL.<br>
<br>
Jason<br>
<br>
</font> <br>
<fieldset class="moz-mime-attachment-header"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
gdal-dev mailing list
<a class="moz-txt-link-abbreviated moz-txt-link-freetext" href="mailto:gdal-dev@lists.osgeo.org" moz-do-not-send="true">gdal-dev@lists.osgeo.org</a>
<a class="moz-txt-link-freetext" href="https://lists.osgeo.org/mailman/listinfo/gdal-dev" originalsrc="https://lists.osgeo.org/mailman/listinfo/gdal-dev" moz-do-not-send="true">https://lists.osgeo.org/mailman/listinfo/gdal-dev</a>
</pre>
</blockquote>
<pre class="moz-signature" cols="72">--
<a class="moz-txt-link-freetext" href="http://www.spatialys.com/" originalsrc="http://www.spatialys.com/" moz-do-not-send="true">http://www.spatialys.com</a>
My software is free, but my time generally not.</pre>
</blockquote>
<br>
</blockquote>
<pre class="moz-signature" cols="72">--
<a class="moz-txt-link-freetext" href="http://www.spatialys.com/" originalsrc="http://www.spatialys.com/" moz-do-not-send="true">http://www.spatialys.com</a>
My software is free, but my time generally not.</pre>
</blockquote>
<br>
</body>
</html>