| 1523 | """ |
| 1524 | |
| 1525 | def __init__( |
| 1526 | self, |
| 1527 | geo_data: Any, |
| 1528 | data: Optional[Any] = None, |
| 1529 | columns: Optional[Sequence[Any]] = None, |
| 1530 | key_on: Optional[str] = None, |
| 1531 | bins: Union[int, Sequence[float]] = 6, |
| 1532 | fill_color: Optional[str] = None, |
| 1533 | nan_fill_color: str = "black", |
| 1534 | fill_opacity: float = 0.6, |
| 1535 | nan_fill_opacity: Optional[float] = None, |
| 1536 | line_color: str = "black", |
| 1537 | line_weight: float = 1, |
| 1538 | line_opacity: float = 1, |
| 1539 | name: Optional[str] = None, |
| 1540 | legend_name: str = "", |
| 1541 | overlay: bool = True, |
| 1542 | control: bool = True, |
| 1543 | show: bool = True, |
| 1544 | topojson: Optional[str] = None, |
| 1545 | smooth_factor: Optional[float] = None, |
| 1546 | highlight: bool = False, |
| 1547 | use_jenks: bool = False, |
| 1548 | **kwargs, |
| 1549 | ): |
| 1550 | super().__init__(name=name, overlay=overlay, control=control, show=show) |
| 1551 | self._name = "Choropleth" |
| 1552 | |
| 1553 | fill_color = fill_color or ("blue" if data is None else "Blues") |
| 1554 | |
| 1555 | if data is not None and not color_brewer(fill_color): |
| 1556 | raise ValueError( |
| 1557 | "Please pass a valid color brewer code to " |
| 1558 | "fill_local. See docstring for valid codes." |
| 1559 | ) |
| 1560 | |
| 1561 | if nan_fill_opacity is None: |
| 1562 | nan_fill_opacity = fill_opacity |
| 1563 | |
| 1564 | if "threshold_scale" in kwargs: |
| 1565 | if kwargs["threshold_scale"] is not None: |
| 1566 | bins = kwargs["threshold_scale"] |
| 1567 | warnings.warn( |
| 1568 | "choropleth `threshold_scale` parameter is now depreciated " |
| 1569 | "in favor of the `bins` parameter.", |
| 1570 | DeprecationWarning, |
| 1571 | ) |
| 1572 | |
| 1573 | # Create color_data dict |
| 1574 | if hasattr(data, "set_index"): |
| 1575 | # This is a pd.DataFrame |
| 1576 | assert columns is not None |
| 1577 | color_data = data.set_index(columns[0])[columns[1]].to_dict() # type: ignore |
| 1578 | elif hasattr(data, "to_dict"): |
| 1579 | # This is a pd.Series |
| 1580 | color_data = data.to_dict() # type: ignore |
| 1581 | elif data: |
| 1582 | color_data = dict(data) |