@@ -59,8 +59,7 @@ def _parse_subtype(cls, dtype_string):
59
59
elif dtype_string == cls ._geometry_name .lower ():
60
60
subtype_string = 'float64'
61
61
else :
62
- raise ValueError ("Cannot parse {dtype_string}" .format (
63
- dtype_string = dtype_string ))
62
+ raise ValueError (f"Cannot parse { dtype_string } " )
64
63
65
64
return subtype_string
66
65
@@ -73,10 +72,9 @@ def construct_from_string(cls, string):
73
72
raise AttributeError
74
73
except AttributeError :
75
74
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 )} " )
78
76
79
- msg = "Cannot construct a '%s ' from '{}'" % cls . __name__
77
+ msg = f "Cannot construct a '{ cls . __name__ } ' from '{{}}'"
80
78
if string .startswith (cls ._geometry_name .lower ()):
81
79
# Extract subtype
82
80
try :
@@ -95,7 +93,7 @@ def __init__(self, subtype):
95
93
96
94
# Validate the subtype is numeric
97
95
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 } '" )
99
97
100
98
array_type = self .construct_array_type ()
101
99
self .arrow_dtype = array_type ._arrow_type_from_numpy_element_dtype (subtype )
@@ -104,10 +102,10 @@ def __hash__(self):
104
102
return hash ((self .__class__ , self .arrow_dtype ))
105
103
106
104
def __str__ (self ):
107
- return "{ }[{}]" . format ( self ._geometry_name , str ( self . subtype .name ))
105
+ return f" { self . _geometry_name } [{ self .subtype .name !s } ]"
108
106
109
107
def __repr__ (self ):
110
- return "{}({})" . format ( self .__class__ .__name__ , str ( self .subtype .name ))
108
+ return f" { self .__class__ .__name__ } ( { self .subtype .name !s } )"
111
109
112
110
@property
113
111
def type (self ):
@@ -137,7 +135,7 @@ def __init__(self, data, dtype=None):
137
135
self .data = pa .array ([data ])[0 ]
138
136
139
137
def __repr__ (self ):
140
- return "{}({})" . format ( self .__class__ .__name__ , self .data .as_py ())
138
+ return f" { self .__class__ .__name__ } ( { self .data .as_py ()} )"
141
139
142
140
def __hash__ (self ):
143
141
return hash ((self .__class__ , np .array (self .data .as_py ()).tobytes ()))
@@ -172,7 +170,7 @@ def intersects_bounds(self, bounds):
172
170
173
171
def intersects (self , shape ):
174
172
raise NotImplementedError (
175
- "intersects not yet implemented for %s objects" % type (self ).__name__
173
+ f "intersects not yet implemented for { type (self ).__name__ } objects"
176
174
)
177
175
178
176
@@ -247,9 +245,7 @@ def __init__(self, array, dtype=None, copy=None):
247
245
array = pa .concat_arrays (array .chunks )
248
246
else :
249
247
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 )} "
253
249
)
254
250
255
251
# Save off pyarrow array
@@ -326,13 +322,10 @@ def copy(self):
326
322
def __eq__ (self , other ):
327
323
if type (other ) is type (self ):
328
324
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 )} """ )
336
329
result = np .zeros (len (self ), dtype = np .bool_ )
337
330
for i in range (len (self )):
338
331
result [i ] = self [i ] == other [i ]
@@ -342,9 +335,9 @@ def __eq__(self, other):
342
335
for i in range (len (self )):
343
336
result [i ] = self [i ] == other
344
337
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 } """ )
348
341
349
342
def __contains__ (self , item ) -> bool :
350
343
raise NotImplementedError
@@ -364,7 +357,7 @@ def __getitem__(self, item):
364
357
if isinstance (item , Integral ):
365
358
item = int (item )
366
359
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" )
368
361
else :
369
362
# Convert negative item index
370
363
if item < 0 :
@@ -396,8 +389,8 @@ def __getitem__(self, item):
396
389
# Check mask length is compatible
397
390
if len (item ) != len (self ):
398
391
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
+
401
394
)
402
395
403
396
# check for NA values
@@ -429,9 +422,7 @@ def take(self, indices, allow_fill=False, fill_value=None):
429
422
# Validate self non-empty (Pandas expects this error when array is empty)
430
423
if (len (self ) == 0 and len (indices ) > 0 and
431
424
(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__ } " )
435
426
436
427
# Validate fill values
437
428
if allow_fill and not (
@@ -447,24 +438,17 @@ def take(self, indices, allow_fill=False, fill_value=None):
447
438
448
439
if any (invalid_mask ):
449
440
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 ]} "
456
443
)
457
444
458
445
if allow_fill :
459
446
invalid_mask = indices < - 1
460
447
if any (invalid_mask ):
461
448
# ValueError expected by pandas ExtensionArray test suite
462
449
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 ]} "
468
452
)
469
453
470
454
# Build pyarrow array of indices
@@ -523,8 +507,8 @@ def fillna(self, value=None, method=None, limit=None):
523
507
if is_array_like (value ):
524
508
if len (value ) != len (self ):
525
509
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 )} "
528
512
)
529
513
value = value [mask ]
530
514
@@ -636,7 +620,7 @@ def intersects(self, shape, inds=None):
636
620
with the supplied shape
637
621
"""
638
622
raise NotImplementedError (
639
- "intersects not yet implemented for %s objects" % type (self ).__name__
623
+ f "intersects not yet implemented for { type (self ).__name__ } objects"
640
624
)
641
625
642
626
def _pad_or_backfill (self , method , ** kwargs ):
0 commit comments