Skip to content

Commit ecdb65e

Browse files
authored
Enable upgrade rules (#153)
1 parent 469c432 commit ecdb65e

File tree

14 files changed

+90
-120
lines changed

14 files changed

+90
-120
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ select = [
9393
"PLR",
9494
"PLW",
9595
"RUF",
96-
# "UP",
96+
"UP",
9797
"W",
9898
]
9999
ignore = [

spatialpandas/dask.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,7 @@ def rm_retry(file_path):
271271
filesystem.rm(file_path, recursive=True)
272272
if filesystem.exists(file_path):
273273
# Make sure we keep retrying until file does not exist
274-
raise ValueError("Deletion of {path} not yet complete".format(
275-
path=file_path
276-
))
274+
raise ValueError(f"Deletion of {file_path} not yet complete")
277275

278276
@retryit
279277
def mkdirs_retry(dir_path):
@@ -301,11 +299,9 @@ def move_retry(p1, p2):
301299
tempdir_format = os.path.join(path, "part.{partition}.parquet")
302300
elif not isinstance(tempdir_format, str) or "{partition" not in tempdir_format:
303301
raise ValueError(
304-
"tempdir_format must be a string containing a {{partition}} "
302+
"tempdir_format must be a string containing a {partition} "
305303
"replacement field\n"
306-
" Received: {tempdir_format}".format(
307-
tempdir_format=repr(tempdir_format)
308-
)
304+
f" Received: {tempdir_format!r}"
309305
)
310306

311307
# Compute number of output partitions
@@ -419,15 +415,10 @@ def read_parquet_retry(parts_tmp_path, subpart_paths, part_output_path):
419415
extras = set(ls_res) - set(subpart_paths)
420416
raise ValueError(
421417
"Filesystem not yet consistent\n"
422-
" Expected len: {expected}\n"
423-
" Found len: {received}\n"
424-
" Missing: {missing}\n"
425-
" Extras: {extras}".format(
426-
expected=len(subpart_paths),
427-
received=len(ls_res),
428-
missing=list(missing),
429-
extras=list(extras)
430-
)
418+
f" Expected len: {len(subpart_paths)}\n"
419+
f" Found len: {len(ls_res)}\n"
420+
f" Missing: {list(missing)}\n"
421+
f" Extras: {list(extras)}"
431422
)
432423
return read_parquet(
433424
parts_tmp_path,

spatialpandas/geometry/base.py

Lines changed: 27 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ def _parse_subtype(cls, dtype_string):
5959
elif dtype_string == cls._geometry_name.lower():
6060
subtype_string = 'float64'
6161
else:
62-
raise ValueError("Cannot parse {dtype_string}".format(
63-
dtype_string=dtype_string))
62+
raise ValueError(f"Cannot parse {dtype_string}")
6463

6564
return subtype_string
6665

@@ -73,10 +72,9 @@ def construct_from_string(cls, string):
7372
raise AttributeError
7473
except AttributeError:
7574
raise TypeError(
76-
"'construct_from_string' expects a string, got {typ}".format(
77-
typ=type(string)))
75+
f"'construct_from_string' expects a string, got {type(string)}")
7876

79-
msg = "Cannot construct a '%s' from '{}'" % cls.__name__
77+
msg = f"Cannot construct a '{cls.__name__}' from '{{}}'"
8078
if string.startswith(cls._geometry_name.lower()):
8179
# Extract subtype
8280
try:
@@ -95,7 +93,7 @@ def __init__(self, subtype):
9593

9694
# Validate the subtype is numeric
9795
if self.subtype.kind not in ('i', 'u', 'f'):
98-
raise ValueError("Received non-numeric type of kind '{}'".format(self.kind))
96+
raise ValueError(f"Received non-numeric type of kind '{self.kind}'")
9997

10098
array_type = self.construct_array_type()
10199
self.arrow_dtype = array_type._arrow_type_from_numpy_element_dtype(subtype)
@@ -104,10 +102,10 @@ def __hash__(self):
104102
return hash((self.__class__, self.arrow_dtype))
105103

106104
def __str__(self):
107-
return "{}[{}]".format(self._geometry_name, str(self.subtype.name))
105+
return f"{self._geometry_name}[{self.subtype.name!s}]"
108106

109107
def __repr__(self):
110-
return "{}({})".format(self.__class__.__name__, str(self.subtype.name))
108+
return f"{self.__class__.__name__}({self.subtype.name!s})"
111109

112110
@property
113111
def type(self):
@@ -137,7 +135,7 @@ def __init__(self, data, dtype=None):
137135
self.data = pa.array([data])[0]
138136

139137
def __repr__(self):
140-
return "{}({})".format(self.__class__.__name__, self.data.as_py())
138+
return f"{self.__class__.__name__}({self.data.as_py()})"
141139

142140
def __hash__(self):
143141
return hash((self.__class__, np.array(self.data.as_py()).tobytes()))
@@ -172,7 +170,7 @@ def intersects_bounds(self, bounds):
172170

173171
def intersects(self, shape):
174172
raise NotImplementedError(
175-
"intersects not yet implemented for %s objects" % type(self).__name__
173+
f"intersects not yet implemented for {type(self).__name__} objects"
176174
)
177175

178176

@@ -247,9 +245,7 @@ def __init__(self, array, dtype=None, copy=None):
247245
array = pa.concat_arrays(array.chunks)
248246
else:
249247
raise ValueError(
250-
"Unsupported type passed for {}: {}".format(
251-
self.__class__.__name__, type(array)
252-
)
248+
f"Unsupported type passed for {self.__class__.__name__}: {type(array)}"
253249
)
254250

255251
# Save off pyarrow array
@@ -326,13 +322,10 @@ def copy(self):
326322
def __eq__(self, other):
327323
if type(other) is type(self):
328324
if len(other) != len(self):
329-
raise ValueError("""
330-
Cannot check equality of {typ} instances of unequal length
331-
len(ra1) == {len_a1}
332-
len(ra2) == {len_a2}""".format(
333-
typ=type(self).__name__,
334-
len_a1=len(self),
335-
len_a2=len(other)))
325+
raise ValueError(f"""
326+
Cannot check equality of {type(self).__name__} instances of unequal length
327+
len(ra1) == {len(self)}
328+
len(ra2) == {len(other)}""")
336329
result = np.zeros(len(self), dtype=np.bool_)
337330
for i in range(len(self)):
338331
result[i] = self[i] == other[i]
@@ -342,9 +335,9 @@ def __eq__(self, other):
342335
for i in range(len(self)):
343336
result[i] = self[i] == other
344337
return result
345-
raise ValueError("""
346-
Cannot check equality of {typ} of length {a_len} with:
347-
{other}""".format(typ=type(self).__name__, a_len=len(self), other=repr(other)))
338+
raise ValueError(f"""
339+
Cannot check equality of {type(self).__name__} of length {len(self)} with:
340+
{other!r}""")
348341

349342
def __contains__(self, item) -> bool:
350343
raise NotImplementedError
@@ -364,7 +357,7 @@ def __getitem__(self, item):
364357
if isinstance(item, Integral):
365358
item = int(item)
366359
if item < -len(self) or item >= len(self):
367-
raise IndexError("{item} is out of bounds".format(item=item))
360+
raise IndexError(f"{item} is out of bounds")
368361
else:
369362
# Convert negative item index
370363
if item < 0:
@@ -396,8 +389,8 @@ def __getitem__(self, item):
396389
# Check mask length is compatible
397390
if len(item) != len(self):
398391
raise IndexError(
399-
"Boolean index has wrong length: {} instead of {}"
400-
.format(len(item), len(self))
392+
f"Boolean index has wrong length: {len(item)} instead of {len(self)}"
393+
401394
)
402395

403396
# check for NA values
@@ -429,9 +422,7 @@ def take(self, indices, allow_fill=False, fill_value=None):
429422
# Validate self non-empty (Pandas expects this error when array is empty)
430423
if (len(self) == 0 and len(indices) > 0 and
431424
(not allow_fill or any(indices >= 0))):
432-
raise IndexError("cannot do a non-empty take from an empty axes|out of bounds on {typ}".format(
433-
typ=self.__class__.__name__,
434-
))
425+
raise IndexError(f"cannot do a non-empty take from an empty axes|out of bounds on {self.__class__.__name__}")
435426

436427
# Validate fill values
437428
if allow_fill and not (
@@ -447,24 +438,17 @@ def take(self, indices, allow_fill=False, fill_value=None):
447438

448439
if any(invalid_mask):
449440
raise IndexError(
450-
"Index value out of bounds for {typ} of length {n}: "
451-
"{idx}".format(
452-
typ=self.__class__.__name__,
453-
n=len(self),
454-
idx=indices[invalid_mask][0]
455-
)
441+
f"Index value out of bounds for {self.__class__.__name__} of length {len(self)}: "
442+
f"{indices[invalid_mask][0]}"
456443
)
457444

458445
if allow_fill:
459446
invalid_mask = indices < -1
460447
if any(invalid_mask):
461448
# ValueError expected by pandas ExtensionArray test suite
462449
raise ValueError(
463-
"Invalid index value for {typ} with allow_fill=True: "
464-
"{idx}".format(
465-
typ=self.__class__.__name__,
466-
idx=indices[invalid_mask][0]
467-
)
450+
f"Invalid index value for {self.__class__.__name__} with allow_fill=True: "
451+
f"{indices[invalid_mask][0]}"
468452
)
469453

470454
# Build pyarrow array of indices
@@ -523,8 +507,8 @@ def fillna(self, value=None, method=None, limit=None):
523507
if is_array_like(value):
524508
if len(value) != len(self):
525509
raise ValueError(
526-
"Length of 'value' does not match. Got ({}) "
527-
" expected {}".format(len(value), len(self))
510+
f"Length of 'value' does not match. Got ({len(value)}) "
511+
f" expected {len(self)}"
528512
)
529513
value = value[mask]
530514

@@ -636,7 +620,7 @@ def intersects(self, shape, inds=None):
636620
with the supplied shape
637621
"""
638622
raise NotImplementedError(
639-
"intersects not yet implemented for %s objects" % type(self).__name__
623+
f"intersects not yet implemented for {type(self).__name__} objects"
640624
)
641625

642626
def _pad_or_backfill(self, method, **kwargs):

spatialpandas/geometry/basefixed.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def __len__(self):
3535
return 8 * len(self.data.as_py()) // self.pyarrow_type.bit_width
3636

3737
def __repr__(self):
38-
return "{}({})".format(self.__class__.__name__, self.flat_values.tolist())
38+
return f"{self.__class__.__name__}({self.flat_values.tolist()})"
3939

4040
@property
4141
def flat_values(self):
@@ -71,15 +71,13 @@ def __init__(self, array, dtype=None):
7171

7272
def invalid_array():
7373
err_msg = (
74-
"Invalid array with type {typ}\n"
75-
"A {cls} may be constructed from:\n"
76-
" - A 1-d array with length divisible by {n} of interleaved\n"
74+
f"Invalid array with type {type(array)}\n"
75+
f"A {self.__class__.__name__} may be constructed from:\n"
76+
f" - A 1-d array with length divisible by {self._element_len} of interleaved\n"
7777
" x y coordinates\n"
78-
" - A tuple of {n} 1-d arrays\n"
78+
f" - A tuple of {self._element_len} 1-d arrays\n"
7979
" - A pyarrow.FixedSizeBinaryArray. In this case the dtype\n"
8080
" argument must also be specified"
81-
).format(
82-
typ=type(array), cls=self.__class__.__name__, n=self._element_len,
8381
)
8482
raise ValueError(err_msg)
8583

spatialpandas/geometry/baselist.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,14 @@ def _validate_nested_arrow_type(nesting_levels, pyarrow_type):
2020
for i in range(nesting_levels):
2121
if not isinstance(pyarrow_element_type, pa.ListType):
2222
raise ValueError(
23-
"Expected input data to have {} nested layer(s)".format(
24-
nesting_levels)
23+
f"Expected input data to have {nesting_levels} nested layer(s)"
2524
)
2625
pyarrow_element_type = pyarrow_element_type.value_type
2726
numpy_element_dtype = pyarrow_element_type.to_pandas_dtype()
2827
if (numpy_element_dtype() is None
2928
or numpy_element_dtype().dtype.kind not in ('i', 'u', 'f')):
3029
raise ValueError(
31-
"Invalid nested element type {}, expected numeric type".format(
32-
pyarrow_element_type
33-
))
30+
f"Invalid nested element type {pyarrow_element_type}, expected numeric type")
3431
return pyarrow_element_type
3532

3633

spatialpandas/geometry/line.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ def _shapely_to_coordinates(cls, shape):
3131
# Single line
3232
return np.asarray(shape.coords).ravel()
3333
else:
34-
raise ValueError("""
35-
Received invalid value of type {typ}. Must be an instance of LineString
36-
or LinearRing""".format(typ=type(shape).__name__))
34+
raise ValueError(f"""
35+
Received invalid value of type {type(shape).__name__}. Must be an instance of LineString
36+
or LinearRing""")
3737

3838
def to_shapely(self):
3939
"""

spatialpandas/geometry/multiline.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ def _shapely_to_coordinates(cls, shape):
4141
elif isinstance(shape, (sg.LineString, sg.LinearRing)):
4242
return [np.asarray(shape.coords).ravel()]
4343
else:
44-
raise ValueError("""
45-
Received invalid value of type {typ}. Must be an instance of MultiLineString
46-
""".format(typ=type(shape).__name__))
44+
raise ValueError(f"""
45+
Received invalid value of type {type(shape).__name__}. Must be an instance of MultiLineString
46+
""")
4747

4848
def to_shapely(self):
4949
"""

spatialpandas/geometry/multipoint.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ def _shapely_to_coordinates(cls, shape):
3232
elif isinstance(shape, sg.MultiPoint):
3333
return np.hstack([g.coords for g in shape.geoms]).ravel()
3434
else:
35-
raise ValueError("""
36-
Received invalid value of type {typ}. Must be an instance of Point,
37-
or MultiPoint""".format(typ=type(shape).__name__))
35+
raise ValueError(f"""
36+
Received invalid value of type {type(shape).__name__}. Must be an instance of Point,
37+
or MultiPoint""")
3838

3939
def to_shapely(self):
4040
"""

spatialpandas/geometry/multipolygon.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ def _shapely_to_coordinates(cls, shape):
4949
elif isinstance(shape, sg.Polygon):
5050
return [Polygon._shapely_to_coordinates(shape)]
5151
else:
52-
raise ValueError("""
53-
Received invalid value of type {typ}. Must be an instance of Polygon or MultiPolygon
54-
""".format(typ=type(shape).__name__))
52+
raise ValueError(f"""
53+
Received invalid value of type {type(shape).__name__}. Must be an instance of Polygon or MultiPolygon
54+
""")
5555

5656
def to_shapely(self):
5757
"""

spatialpandas/geometry/point.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ def _shapely_to_coordinates(cls, shape):
2929
# Single point
3030
return np.asarray(shape.coords).ravel()
3131
else:
32-
raise ValueError("""
33-
Received invalid value of type {typ}. Must be an instance of Point,
34-
or MultiPoint""".format(typ=type(shape).__name__))
32+
raise ValueError(f"""
33+
Received invalid value of type {type(shape).__name__}. Must be an instance of Point,
34+
or MultiPoint""")
3535

3636
def to_shapely(self):
3737
"""
@@ -146,7 +146,7 @@ def intersects(self, shape):
146146
elif isinstance(shape, MultiPolygon):
147147
return self._intersects_polygon(shape)
148148
else:
149-
raise ValueError("Unsupported intersection type %s" % type(shape).__name__)
149+
raise ValueError(f"Unsupported intersection type {type(shape).__name__}")
150150

151151

152152
class PointArray(GeometryFixedArray):
@@ -252,7 +252,7 @@ def intersects(self, shape, inds=None):
252252
elif isinstance(shape, MultiPolygon):
253253
return self._intersects_polygon(shape, inds)
254254
else:
255-
raise ValueError("Unsupported intersection type %s" % type(shape).__name__)
255+
raise ValueError(f"Unsupported intersection type {type(shape).__name__}")
256256

257257

258258
@ngpjit

0 commit comments

Comments
 (0)