AttributeError: module 'numpy' has no attribute 'str'

9219
3
Jump to solution
01-13-2023 01:38 AM
BengtDahlgrenStockholmGeo
New Contributor III

Hi,

When trying to run this in VS code

 

m = GIS().map("Vellinge Trangränden", zoomlevel = 16)
m.basemap = 'satellite'
m.center = [55.472155,13.032001]

pd.DataFrame.spatial.from_featureclass(arcpy.env.workspace + "\\Fastighetsgränser_pgon").sort_values(by="Fastighetsägare").spatial.plot(map_widget = m,
    col = 'Fastighetsägare',
    renderer_type = 's',
    #cmap = "Blues",
    alpha = 0.2,
    #polygon_color = [0,0,0,255],
    outline_color = [0,0,0,100],
    outline_width = 0.05
    )

 

 

I get the following error

 

 

c:\Users\user\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone-1\lib\site-packages\arcgis\auth\tools\_lazy.py:48: FutureWarning:

In the future `np.str` will be defined as the corresponding NumPy scalar. (This may have returned Python scalars in past versions.

Output exceeds the size limit. Open the full output data in a text editor
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-13-404f875978ff> in <module>
3 m.center = [55.472155,13.032001]
4
----> 5 pd.DataFrame.spatial.from_featureclass(arcpy.env.workspace + "\\Fastighetsgränser_pgon").sort_values(by="Fastighetsägare").spatial.plot(map_widget = m,
6 # col = 'Fastighetsägare',
7 # renderer_type = 's',

c:\Users\user\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone-1\lib\site-packages\arcgis\features\geo\_accessor.py in plot(self, map_widget, **kwargs)
2311 self._data.columns = [c.replace(" ", "_") for c in self._data.columns]
2312 # plot and be merry
-> 2313 _plot_map_widget(map_widget)
2314 self._data.columns = orig_col
2315 return True

c:\Users\user\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone-1\lib\site-packages\arcgis\features\geo\_accessor.py in _plot_map_widget(mp_wdgt)
2279 # small helper to consolidate the plotting function
2280 def _plot_map_widget(mp_wdgt):
-> 2281 plot(
2282 df=self._data,
2283 map_widget=mp_wdgt,

c:\Users\user\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone-1\lib\site-packages\arcgis\features\geo\_viz\mapping.py in plot(df, map_widget, name, renderer_type, symbol_type, symbol_style, col, colors, alpha, **kwargs)
192 col_old = df.columns.tolist()
...
--> 284 raise AttributeError("module {!r} has no attribute "
285 "{!r}".format(__name__, attr))
286

AttributeError: module 'numpy' has no attribute 'str'

 

 

From Python for the complete error

 

 

Traceback (most recent call last):
  File "n:\PDOC\Vellinge Herrestorp 6_1\22649_ Borrhålsdimensionering\24_Beräkningar\ArcGIS\test_error_numpy.py", line 19, in <module>
    pd.DataFrame.spatial.from_featureclass(arcpy.env.workspace + "\\Fastighetsgränser_pgon").sort_values(by='Fastighetsägare').spatial.plot(map_widget = m,
  File "C:\Users\user\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone-1\lib\site-packages\arcgis\features\geo\_accessor.py", line 2313, in plot
    _plot_map_widget(map_widget)
  File "C:\Users\user\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone-1\lib\site-packages\arcgis\features\geo\_accessor.py", line 2281, in _plot_map_widget
    plot(
  File "C:\Users\user\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone-1\lib\site-packages\arcgis\features\geo\_viz\mapping.py", line 194, in plot
    fc = df.spatial.to_feature_collection(name=name)
  File "C:\Users\user\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone-1\lib\site-packages\arcgis\features\geo\_accessor.py", line 3226, in to_feature_collection
    fs = self.__feature_set__
  File "C:\Users\user\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone-1\lib\site-packages\arcgis\features\geo\_accessor.py", line 2989, in __feature_set__
    if isinstance(col_val, (str, np.str)) and not col in date_cols:
  File "C:\Users\user\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone-1\lib\site-packages\arcgis\auth\tools\_lazy.py", line 48, in __getattr__
    return getattr(self._load(), attrb)
  File "C:\Users\user\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone-1\lib\site-packages\numpy\__init__.py", line 284, in __getattr__
    raise AttributeError("module {!r} has no attribute "
AttributeError: module 'numpy' has no attribute 'str'

 

 

I think, this is related to this issue:

https://levelup.gitconnected.com/fix-attributeerror-module-numpy-has-no-attribute-float-d7d68c5a4971

but I am unsure how to fix it in my case.

  • I recently upgraded ArcGis Pro to v3.0.3 which uses Python 3.9
  • Env: arcgis-py3-clone-1
  • numpy version: 1.24.1 according to pip, 1.20.1 according to the Package Manager in ArcGIS
  • I have a warning filter: 

 

warnings.filterwarnings("ignore", message=r"Passing", category=FutureWarning)

 

Grateful for any help on this issue!

 

 

0 Kudos
1 Solution

Accepted Solutions
BengtDahlgrenStockholmGeo
New Contributor III

Thank you for your answer.

I solved it by removing the np.str and np.int instances in the _accessor.py files, since these will be /are anyway deprecated according to the FutureWarning. Not sure if this is a sustainable solution though.

View solution in original post

0 Kudos
3 Replies
DanPatterson
MVP Esteemed Contributor

sort_values(by=

doesn't look correct


... sort of retired...
0 Kudos
BengtDahlgrenStockholmGeo
New Contributor III

Thank you for your answer.

I solved it by removing the np.str and np.int instances in the _accessor.py files, since these will be /are anyway deprecated according to the FutureWarning. Not sure if this is a sustainable solution though.

0 Kudos
DanPatterson
MVP Esteemed Contributor

It will have to be, since np.str and np.int are being removed, hence the warning you are getting now.  When they are deprecated, you will just get an error message


... sort of retired...