[GRASS-dev] [GRASS GIS] #3391: r.learn.ml : the list of caterory map indices is not handled properly.

#3391: r.learn.ml : the list of caterory map indices is not handled properly.
--------------------+-------------------------
Reporter: maitl | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 7.2.2
Component: Addons | Version: unspecified
Keywords: | CPU: All
Platform: All |
--------------------+-------------------------
# convert to lists
     """
     if ',' in categorymaps:
         categorymaps = [int(i) for i in categorymaps.split(',')]
         print(categorymaps)
     else: categorymaps = None
     """

fails if there is only one category map.

------------------------------------------
The proposed solution is

if categorymaps.strip() == '':
         categorymaps = None
     else:
         try:
             categorymaps = [int(i.strip()) for i in
categorymaps.split(',')]
             # negatiivse ja maplist, _ = maps_from_group(group) suurima
indeksi kontroll, dublikaatide kontroll (unique)
             nCategories = len(maps_from_group(group)[0])
             if min(categorymaps) < 0:
                 gscript.fatal('Category map index can not be negative.')
             if max(categorymaps) > nCategories - 1:
                 gscript.fatal('Category map index input can not exceed ' +
str(nCategories - 1))
             if not len(np.unique(categorymaps)) == len(categorymaps):
                 gscript.fatal('Duplicate indices in category map index
list.')
         except:
             gscript.fatal('Error in category map list input.')

     if ',' in indexes:
         indexes = [int(i) for i in indexes.split(',')]
     else:
         indexes = int(indexes)
     if indexes == -1: indexes = None

# credits for this fix go to Jaan Janno from Tartu University, Estonia

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3391&gt;
GRASS GIS <https://grass.osgeo.org>

#3391: r.learn.ml : the list of caterory map indices is not handled properly.
---------------------+-------------------------
  Reporter: maitl | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone: 7.2.2
Component: Addons | Version: unspecified
Resolution: | Keywords:
       CPU: All | Platform: All
---------------------+-------------------------
Changes (by maitl):

* Attachment "r.learn.ml" added.

The copy of r.learn.ml with bugfix example

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3391&gt;
GRASS GIS <https://grass.osgeo.org>

#3391: r.learn.ml : the list of caterory map indices is not handled properly.
---------------------+-------------------------
  Reporter: maitl | Owner: grass-dev@…
      Type: defect | Status: closed
  Priority: normal | Milestone: 7.2.2
Component: Addons | Version: unspecified
Resolution: fixed | Keywords:
       CPU: All | Platform: All
---------------------+-------------------------
Changes (by spawley):

* status: new => closed
* resolution: => fixed

Comment:

Thanks again for this Jaan, I have updated the Add-Ons with #71358 and I'm
closing the ticket.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3391#comment:1&gt;
GRASS GIS <https://grass.osgeo.org>