Skip to content

Commit 8c01ded

Browse files
committed
fix geopandas inheritance
1 parent c7dd186 commit 8c01ded

4 files changed

Lines changed: 31 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
- **1.0.2** (2026-01-16):
2+
- BREAKING: require cartogram_attribute to be a positional argument
3+
- fix inheritance from geopandas.GeoDataFrame
4+
- update geopandas dependency
5+
16
- **1.0.1** (2025-06-27):
27
- workaround for change in geopandas inheritance
38

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ authors = [
1212
]
1313

1414
dependencies = [
15-
"geopandas<1.1.0",
15+
"geopandas",
1616
"joblib",
1717
"numpy",
1818
"pandas",

src/cartogram/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
"""Compute continuous cartograms."""
44

5-
__version__ = "1.0.1"
5+
__version__ = "1.0.2"
66

77
from .cartogram import Cartogram
88

src/cartogram/cartogram.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,33 @@
3434
class Cartogram(geopandas.GeoDataFrame):
3535
"""Compute continuous cartograms."""
3636

37+
_constructor = geopandas.GeoDataFrame
38+
39+
_constructor_sliced = pandas.Series
40+
41+
@classmethod
42+
def _geodataframe_constructor_with_fallback(
43+
cls, *args, **kwargs
44+
):
45+
"""
46+
A flexible constructor for Cartogram.
47+
48+
It which checks whether or not arguments of the child class are used.
49+
"""
50+
if "cartogram_attribute" in kwargs.keys():
51+
df = cls(*args, **kwargs)
52+
else:
53+
df = geopandas.GeoDataFrame(*args, **kwargs)
54+
geometry_cols_mask = df.dtypes == "geometry"
55+
if len(geometry_cols_mask) == 0 or geometry_cols_mask.sum() == 0:
56+
df = pandas.DataFrame(df)
57+
58+
return df
59+
3760
def __init__(
3861
self,
3962
input_polygon_geodataframe,
63+
/,
4064
cartogram_attribute,
4165
max_iterations=10,
4266
max_average_error=0.1,

0 commit comments

Comments
 (0)