docstr: Categorical maps
docstr_tok: ["Categorical","maps"]
code: def test_categorical(self):
      """Categorical maps"""
      # auto detection
      m = self.world.explore(column="continent")
      out_str = self._fetch_map_string(m)
      assert 'color":"#9467bd","continent":"Europe"' in out_str
      assert 'color":"#c49c94","continent":"NorthAmerica"' in out_str
      assert 'color":"#1f77b4","continent":"Africa"' in out_str
      assert 'color":"#98df8a","continent":"Asia"' in out_str
      assert 'color":"#ff7f0e","continent":"Antarctica"' in out_str
      assert 'color":"#9edae5","continent":"SouthAmerica"' in out_str
      assert 'color":"#7f7f7f","continent":"Oceania"' in out_str
      assert (
          'color":"#dbdb8d","continent":"Sevenseas(openocean)"'
          in out_str
      )
  
      # forced categorical
      m = self.nybb.explore(column="BoroCode", categorical=True)
      out_str = self._fetch_map_string(m)
      assert 'color":"#9edae5"' in out_str
      assert 'color":"#c7c7c7"' in out_str
      assert 'color":"#8c564b"' in out_str
      assert 'color":"#1f77b4"' in out_str
      assert 'color":"#98df8a"' in out_str
  
      # pandas.Categorical
      df = self.world.copy()
      df["categorical"] = pd.Categorical(df["name"])
      m = df.explore(column="categorical")
      out_str = self._fetch_map_string(m)
      for c in np.apply_along_axis(
          colors.to_hex, 1, cm.tab20(range(20))
      ):
          assert f'"fillColor":"{c}"' in out_str
  
      # custom cmap
      m = self.nybb.explore(column="BoroName", cmap="Set1")
      out_str = self._fetch_map_string(m)
      assert 'color":"#999999"' in out_str
      assert 'color":"#a65628"' in out_str
      assert 'color":"#4daf4a"' in out_str
      assert 'color":"#e41a1c"' in out_str
      assert 'color":"#ff7f00"' in out_str
  
      # custom list of colors
      cmap = ["#333432", "#3b6e8c", "#bc5b4f", "#8fa37e", "#efc758"]
      m = self.nybb.explore(column="BoroName", cmap=cmap)
      out_str = self._fetch_map_string(m)
      for c in cmap:
          assert f'"fillColor":"{c}"' in out_str
  
      # shorter list (to make it repeat)
      cmap = ["#333432", "#3b6e8c"]
      m = self.nybb.explore(column="BoroName", cmap=cmap)
      out_str = self._fetch_map_string(m)
      for c in cmap:
          assert f'"fillColor":"{c}"' in out_str
  
      with pytest.raises(ValueError, match="'cmap' is invalid."):
          self.nybb.explore(column="BoroName", cmap="nonsense")
  
imports: import geopandas
  import numpy
  import pandas
  import pytest
  import shapely
  from packaging.version import Version
  from matplotlib import cm
  from matplotlib import colors
  from branca.colormap import StepColormap
label_desc: Use image node_id 9 for calling the TestExplore obj's underlying member method code with example usage: obj.test_categorical() without return types