Skip to content

Commit

Permalink
Update to f-string with small manual changes
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxbro committed Nov 4, 2022
1 parent 3416921 commit 4711233
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion holoviews/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def __call__(self, *args, **opts): # noqa (dummy signature)
try:
exec(code)
except Exception as e:
print("Warning: Could not load %r [%r]" % (filename, str(e)))
print(f"Warning: Could not load {filename!r} [{str(e)!r}]")
del f, code
break
del filename
Expand Down
2 changes: 1 addition & 1 deletion holoviews/core/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ def __getitem__(self, key):
idx = row * self._max_cols + col
keys = list(self.data.keys())
if idx >= len(keys) or col >= self._max_cols:
raise KeyError('Index %s is outside available item range' % str(key))
raise KeyError(f'Index {key} is outside available item range')
key = keys[idx]
return super().__getitem__(key)

Expand Down
2 changes: 1 addition & 1 deletion holoviews/core/spaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ def _initial_key(self):
if undefined:
msg = ('Dimension(s) {undefined_dims} do not specify range or values needed '
'to generate initial key')
undefined_dims = ', '.join(['%r' % str(dim) for dim in undefined])
undefined_dims = ', '.join(f'{str(dim)!r}' for dim in undefined)
raise KeyError(msg.format(undefined_dims=undefined_dims))

return tuple(key)
Expand Down
4 changes: 2 additions & 2 deletions holoviews/element/comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def compare_lists(cls, l1, l2, msg=None):
for v1, v2 in zip(l1, l2):
cls.assertEqual(v1, v2)
except AssertionError:
raise AssertionError(msg or '%s != %s' % (repr(l1), repr(l2)))
raise AssertionError(msg or f'{l1!r} != {l2!r}')


@classmethod
Expand All @@ -237,7 +237,7 @@ def compare_tuples(cls, t1, t2, msg=None):
for i1, i2 in zip(t1, t2):
cls.assertEqual(i1, i2)
except AssertionError:
raise AssertionError(msg or '%s != %s' % (repr(t1), repr(t2)))
raise AssertionError(msg or f'{t1!r} != {t2!r}')


#=====================#
Expand Down
2 changes: 1 addition & 1 deletion holoviews/plotting/mpl/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ def _compute_ticks(self, element, edges, widths, lims):
if self.cyclic:
x0, x1, _, _ = lims
xvals = np.linspace(x0, x1, self.xticks)
labels = ["%.0f" % np.rad2deg(x) + '\N{DEGREE SIGN}' for x in xvals]
labels = [f"{np.rad2deg(x):.0f}\N{DEGREE SIGN}" for x in xvals]
elif self.xticks:
dim = element.get_dimension(0)
inds = np.linspace(0, len(edges), self.xticks, dtype=np.int)
Expand Down
2 changes: 1 addition & 1 deletion holoviews/plotting/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1293,7 +1293,7 @@ def _process(self, element, key=None):
[1, 0.99989, 0.93683 ], [1, 1, 1 ]]

# Bokeh palette
fire = [str('#{0:02x}{1:02x}{2:02x}'.format(int(r*255),int(g*255),int(b*255)))
fire = [f'#{int(r * 255):02x}{int(g * 255):02x}{int(b * 255):02x}'
for r,g,b in fire_colors]


Expand Down
2 changes: 1 addition & 1 deletion holoviews/tests/core/test_archives.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def test_filearchive_json_single_file(self):
self.assertEqual(len(archive), 1)
self.assertEqual(archive.listing(), ['metadata.json'])
archive.export()
fname = '%s_%s' % (export_name, 'metadata.json')
fname = f"{export_name}_metadata.json"
if not os.path.isfile(fname):
raise AssertionError(f"No file {fname!r} created on export.")
self.assertEqual(json.load(open(fname, 'r')), data)
Expand Down
2 changes: 1 addition & 1 deletion holoviews/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def _expand_options(cls, options, backend=None):
try:
backend_options = Store.options(backend=backend or current_backend)
except KeyError as e:
raise Exception('The %s backend is not loaded. Please load the backend using hv.extension.' % str(e))
raise Exception(f'The {e} backend is not loaded. Please load the backend using hv.extension.')
expanded = {}
if isinstance(options, list):
options = merge_options_to_dict(options)
Expand Down
4 changes: 2 additions & 2 deletions holoviews/util/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def extract_keywords(cls, line, items):
raise SyntaxError(f"Invalid keyword: {value.split()[-1]}")
keyword = f'{key}={value}'
try:
items.update(eval('dict(%s)' % keyword))
items.update(eval(f'dict({keyword})'))
except:
raise SyntaxError(f"Could not evaluate keyword: {keyword}")
return items
Expand Down Expand Up @@ -326,7 +326,7 @@ def output(cls, line=None, cell=None, cell_runner=None,
"has not been loaded, ensure you load it "
"with hv.extension({ext}) before using "
"hv.output.".format(ext=repr(backend)))
print('Error: %s' % str(e))
print(f'Error: {str(e)}')
if help_prompt:
print(help_prompt)
return
Expand Down
4 changes: 2 additions & 2 deletions holoviews/util/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -825,9 +825,9 @@ def __repr__(self):
fn_name = self._numpy_funcs[fn]
format_string = prev+').{fn}('
elif isinstance(fn, iloc):
format_string = prev+').iloc[{0}]'.format(repr(fn.index))
format_string = prev+f').iloc[{fn.index!r}]'
elif isinstance(fn, loc):
format_string = prev+').loc[{0}]'.format(repr(fn.index))
format_string = prev+f').loc[{fn.index!r}]'
elif fn in self._custom_funcs:
fn_name = self._custom_funcs[fn]
format_string = prev+').{fn}('
Expand Down

0 comments on commit 4711233

Please sign in to comment.