1313import pandas
1414import shapely
1515
16-
1716__all__ = ["Cartogram" ]
1817
1918
@@ -39,15 +38,13 @@ class Cartogram(geopandas.GeoDataFrame):
3938 _constructor_sliced = pandas .Series
4039
4140 @classmethod
42- def _geodataframe_constructor_with_fallback (
43- cls , * args , ** kwargs
44- ):
41+ def _geodataframe_constructor_with_fallback (cls , * args , ** kwargs ):
4542 """
46- A flexible constructor for Cartogram.
43+ Provide a flexible constructor for Cartogram.
4744
4845 Checks whether or not arguments of the child class are used.
4946 """
50- if "cartogram_attribute" in kwargs . keys () :
47+ if "cartogram_attribute" in kwargs :
5148 df = cls (* args , ** kwargs )
5249 else :
5350 df = geopandas .GeoDataFrame (* args , ** kwargs )
@@ -131,7 +128,8 @@ def _check_geodata(self):
131128 for geometry_type in geometry_types :
132129 if geometry_type not in ["MultiPolygon" , "Polygon" ]:
133130 raise ValueError (
134- f"Only POLYGON or MULTIPOLYGON geometries supported, found { geometry_type } ."
131+ "Only POLYGON or MULTIPOLYGON geometries supported, "
132+ f"found { geometry_type } ."
135133 )
136134 self ._input_is_multipolygon = "MultiPolygon" in geometry_types
137135
@@ -179,15 +177,17 @@ def _feature_error(self, feature):
179177
180178 return error
181179
182- def _invalidate_cached_properties (self , properties = [] ):
180+ def _invalidate_cached_properties (self , properties = None ):
183181 """Invalidate properties that were cached as `functools.cached_property`."""
184182 # https://stackoverflow.com/a/68316608
185183 if not properties :
186184 # # clear all as default
187185 # properties = [
188186 # attribute
189187 # for attribute in self.__dict__.keys()
190- # if isinstance(getattr(self, attribute, None), functools.cached_property)
188+ # if isinstance(
189+ # getattr(self, attribute, None),
190+ # functools.cached_property)
191191 # ]
192192 properties = [
193193 attr
@@ -215,7 +215,12 @@ def _transform(self):
215215 self .iteration < self .max_iterations
216216 and self .average_error > self .max_average_error
217217 ):
218- # self.geometry = self.geometry.apply(functools.partial(self._transform_geometry, features=self._cartogram_features))
218+ # self.geometry = self.geometry.apply(
219+ # functools.partial(
220+ # self._transform_geometry,
221+ # features=self._cartogram_features
222+ # )
223+ # )
219224 with joblib .Parallel (
220225 verbose = (self .verbose * 10 ),
221226 n_jobs = NUM_THREADS ,
@@ -234,7 +239,8 @@ def _transform(self):
234239 self .iteration += 1
235240 if self .verbose :
236241 print (
237- f"{ self .average_error :0.5f} error left after { self .iteration :d} iteration(s)"
242+ f"{ self .average_error :0.5f} error left "
243+ f"after { self .iteration :d} iteration(s)"
238244 )
239245
240246 self .geometry = self .geometry .buffer (0.0 )
0 commit comments