question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: Could not load the dataset: Cannot convert non-finite values (NA or inf) to integer by pd.DataFrame.spatial.from_layer

See original GitHub issue

Describe the bug The same code works in Arcpy 2.9/ArcGIS Pro 2.9, and after updated to ArcGIS Pro 3.0/Arcpy 3.0, the code got the below error.

error: ``` _Traceback (most recent call last): File “C:\Users\hd\AppData\Local\ESRI\conda\envs\arcgispro_py3_clone\lib\site-packages\arcgis\features\geo_accessor.py”, line 2688, in from_layer return from_layer(layer=layer) File “C:\Users\hd\AppData\Local\ESRI\conda\envs\arcgispro_py3_clone\lib\site-packages\arcgis\features\geo_io\serviceops.py”, line 187, in from_layer sdf = layer.query(where=query, as_df=True) File “C:\Users\hd\AppData\Local\ESRI\conda\envs\arcgispro_py3_clone\lib\site-packages\arcgis\features\layer.py”, line 1856, in query df = self._query_df(url, params) File “C:\Users\hd\AppData\Local\ESRI\conda\envs\arcgispro_py3_clone\lib\site-packages\arcgis\features\layer.py”, line 3308, in _query_df df = df.astype(dtypes) File “C:\Users\hd\AppData\Local\ESRI\conda\envs\arcgispro_py3_clone\lib\site-packages\pandas\core\generic.py”, line 5799, in astype col.astype(dtype=dtype[col_name], copy=copy, errors=errors) File “C:\Users\hd\AppData\Local\ESRI\conda\envs\arcgispro_py3_clone\lib\site-packages\pandas\core\generic.py”, line 5815, in astype new_data = self._mgr.astype(dtype=dtype, copy=copy, errors=errors) File “C:\Users\hd\AppData\Local\ESRI\conda\envs\arcgispro_py3_clone\lib\site-packages\pandas\core\internals\managers.py”, line 418, in astype return self.apply(“astype”, dtype=dtype, copy=copy, errors=errors) File “C:\Users\hd\AppData\Local\ESRI\conda\envs\arcgispro_py3_clone\lib\site-packages\pandas\core\internals\managers.py”, line 327, in apply applied = getattr(b, f)(**kwargs) File “C:\Users\hd\AppData\Local\ESRI\conda\envs\arcgispro_py3_clone\lib\site-packages\pandas\core\internals\blocks.py”, line 591, in astype new_values = astype_array_safe(values, dtype, copy=copy, errors=errors) File “C:\Users\hd\AppData\Local\ESRI\conda\envs\arcgispro_py3_clone\lib\site-packages\pandas\core\dtypes\cast.py”, line 1309, in astype_array_safe new_values = astype_array(values, dtype, copy=copy) File “C:\Users\hd\AppData\Local\ESRI\conda\envs\arcgispro_py3_clone\lib\site-packages\pandas\core\dtypes\cast.py”, line 1257, in astype_array values = astype_nansafe(values, dtype, copy=copy) File “C:\Users\hd\AppData\Local\ESRI\conda\envs\arcgispro_py3_clone\lib\site-packages\pandas\core\dtypes\cast.py”, line 1168, in astype_nansafe return astype_float_to_int_nansafe(arr, dtype, copy) File “C:\Users\hd\AppData\Local\ESRI\conda\envs\arcgispro_py3_clone\lib\site-packages\pandas\core\dtypes\cast.py”, line 1213, in astype_float_to_int_nansafe raise IntCastingNaNError( pandas.errors.IntCastingNaNError: Cannot convert non-finite values (NA or inf) to integer

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File “<string>”, line 1, in <module> File “C:\Users\hd\AppData\Local\ESRI\conda\envs\arcgispro_py3_clone\lib\site-packages\arcgis\features\geo_accessor.py”, line 2697, in from_layer raise Exception(“Could not load the dataset: %s” % str(e)) Exception: Could not load the dataset: Cannot convert non-finite values (NA or inf) to integer_ ```

Platform (please complete the following information):

  • OS: Windows 11
  • Python API Version : 2.0.1

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
EricSamsonCartocommented, Sep 27, 2022

@sstrack265 You could downgrade the API version to 2.0.0, just know that if you plan on using this environment within ArcGIS pro, it will no longer be compatible. You will have to make/use a different python environment within ArcGIS Pro. The newest version of ArcGIS Pro requires that its python environment has the newest version of the API installed.

Outside of downgrading the package, options are:

  1. Replace the null values in the integer field(s) with an integer.
  2. Exclude all of your integer fields when calling the .query() method. The .query() method has a parameter to specify the output fields: featurelayer

I understand neither of these options are entirely possible/advantageous for some workflows.

0reactions
sstrack265commented, Sep 27, 2022

Do we have any idea of when a 3.1.0 release would be? And is there a suggested work around in the meantime- such as using an older version of Python API?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Data type conversion error: ValueError: Cannot convert non ...
python - Data type conversion error: ValueError: Cannot convert non-finite values (NA or inf) to integer - Stack Overflow. Stack Overflow for ...
Read more >
Cannot convert non-finite values (NA or inf) to integer
I wanted to load the results as a spatially enabled dataframe using the ArcGIS API for Python, in a Notebook currently but will...
Read more >
Valueerror: cannot convert non-finite values (na or inf) to integer
Valueerror: cannot convert non-finite values (na or inf) to integer. The dic column in the data frame below contains nan and float values....
Read more >
IntCastingNaNError: Cannot convert non-finite values (NA or ...
I want to transform dask bag to dask dataframe and then to pandas dataframe. This is my snippet. %%time bag = dask_mongo.read_mongo( database=" ......
Read more >
Need help with type conversion | Data Science and Machine ...
How would I convert a float to an int, I tried astype but have me an error "Cannot convert non-finite values (NA or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found