Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
66b3a5a
Refactor using f-string instead of string.format
chilin0525 Feb 25, 2025
f5b0933
Refactor using f-string instead of string.format
chilin0525 Feb 28, 2025
a5c1112
Merge branch 'main' into using-f-string-instead-string-format
chilin0525 Feb 28, 2025
4b46338
Rollback _filesystem_uri to test fail testcase on CI
chilin0525 Mar 1, 2025
02cbd03
Refactor using f-string instead of string.format
chilin0525 Mar 1, 2025
e63da8b
Refactor using f-string instead of string.format
chilin0525 Mar 1, 2025
edab1db
Refactor using f-string instead of string.format
chilin0525 Mar 1, 2025
0b9b9e8
Fix inconsistent f-string format in Tensor.repr method
chilin0525 Mar 3, 2025
c711cb0
Fix Tensor.repr method by using proper f-string formatting
chilin0525 Mar 3, 2025
965d70a
Merge branch 'main' into using-f-string-instead-string-format
chilin0525 Mar 8, 2025
6cc308f
Refactor using f-string instead of string.format for all files outsid…
chilin0525 Mar 8, 2025
cef7a3b
Remove to call str function in f-string
chilin0525 Mar 9, 2025
ffc9335
Refactor using f-string instead of string.format
chilin0525 Mar 9, 2025
906b7a8
Resolve conflict in _parquet.pyx
chilin0525 Mar 11, 2025
826b248
Merge branch 'main' into using-f-string-instead-string-format
chilin0525 Apr 6, 2025
558be8d
using variable to prevent f-string too long
chilin0525 Apr 6, 2025
c926dde
remove unnecessary str() from f-string
chilin0525 Apr 6, 2025
97070b2
rollback from f-string to string formating in bot.py
chilin0525 Apr 6, 2025
2c7c552
remove unnecessary f prefixes in f-string
chilin0525 Apr 6, 2025
79d9aa0
trigger GitHub actions
chilin0525 Apr 6, 2025
e6d63dd
fix incorrect use of '{{{{' in f-string formatting
chilin0525 Apr 6, 2025
ffe19ed
remove all file contains unnecessary f prefixes in f-string
chilin0525 Apr 6, 2025
471192d
fix missing f prefix in f-string in feather.py
chilin0525 Apr 6, 2025
cfebe1f
test CI
chilin0525 Apr 6, 2025
146e79e
Merge branch 'main' into using-f-string-instead-string-format
chilin0525 Apr 13, 2025
6f0f7ca
fix conflict
chilin0525 May 10, 2025
7f20c82
Merge branch 'main' into using-f-string-instead-string-format
raulcd May 12, 2025
7079403
Apply suggestions from code review
raulcd May 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cpp/build-support/asan_symbolize.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def symbolize(self, addr, binary, offset):
# foo(type1, type2) (in object.name) (filename.cc:80)
match = re.match(r'^(.*) \(in (.*)\) \((.*:\d*)\)$', atos_line)
if DEBUG:
print('atos_line: {0}'.format(atos_line))
print(f'atos_line: {atos_line}')
if match:
function_name = match.group(1)
function_name = re.sub(r'\(.*?\)', '', function_name)
Expand Down
7 changes: 3 additions & 4 deletions cpp/build-support/fuzzing/pack_corpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ def process_dir(corpus_dir, zip_output):

for child in corpus_dir.iterdir():
if not child.is_file():
raise IOError("Not a file: {0}".format(child))
raise IOError(f"Not a file: {child}")
with child.open('rb') as f:
data = f.read()
arcname = hashlib.sha1(data).hexdigest()
if arcname in seen:
raise ValueError("Duplicate hash: {0} (in file {1})"
.format(arcname, child))
raise ValueError(f"Duplicate hash: {arcname} (in file {child})")
zip_output.writestr(str(arcname), data)
seen.add(arcname)

Expand All @@ -49,6 +48,6 @@ def main(corpus_dir, zip_output_name):

if __name__ == "__main__":
if len(sys.argv) != 3:
print("Usage: {0} <corpus dir> <output zip file>".format(sys.argv[0]))
print(f"Usage: {sys.argv[0]} <corpus dir> <output zip file>")
sys.exit(1)
main(sys.argv[1], sys.argv[2])
2 changes: 1 addition & 1 deletion cpp/build-support/iwyu/iwyu_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def main(compilation_db_path, source_files, verbose, formatter, iwyu_args):
if matches:
entries.extend(matches)
else:
print("{} not in compilation database".format(source))
print(f"{source} not in compilation database")
# TODO: As long as there is no complete compilation database available this check cannot be performed
pass
#print('WARNING: \'%s\' not found in compilation database.', source)
Expand Down
4 changes: 2 additions & 2 deletions cpp/build-support/lint_cpp_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def lint_files():
if __name__ == '__main__':
failures = list(lint_files())
for path, why, i, line in failures:
print('File {0} failed C++/CLI lint check: {1}\n'
'Line {2}: {3}'.format(path, why, i + 1, line))
print(f'File {path} failed C++/CLI lint check: {why}\n'
f'Line {i + 1}: {line}')
if failures:
exit(1)
10 changes: 4 additions & 6 deletions cpp/build-support/run_clang_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ def _check_one_file(filename, formatted):
original.decode('utf8').splitlines(True),
formatted.decode('utf8').splitlines(True),
fromfile=filename,
tofile="{} (after clang format)".format(
filename)))
tofile=f"{filename} (after clang format)"))
else:
diff = None

Expand Down Expand Up @@ -85,8 +84,7 @@ def _check_one_file(filename, formatted):

if arguments.fix:
if not arguments.quiet:
print("\n".join(map(lambda x: "Formatting {}".format(x),
formatted_filenames)))
print("\n".join(f"Formatting {x}" for x in formatted_filenames))

# Break clang-format invocations into chunks: each invocation formats
# 16 files. Wait for all processes to complete
Expand Down Expand Up @@ -122,9 +120,9 @@ def _check_one_file(filename, formatted):
# check the output from each invocation of clang-format in parallel
for filename, diff in pool.starmap(_check_one_file, checker_args):
if not arguments.quiet:
print("Checking {}".format(filename))
print(f"Checking {filename}")
if diff:
print("{} had clang-format style issues".format(filename))
print(f"{filename} had clang-format style issues")
# Print out the diff to stderr
error = True
# pad with a newline
Expand Down
2 changes: 1 addition & 1 deletion cpp/build-support/run_cpplint.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def _check_some_files(completed_processes, filenames):
if arguments.quiet:
cmd.append('--quiet')
else:
print("\n".join(map(lambda x: "Linting {}".format(x),
print("\n".join(map(lambda x: f"Linting {x}",
linted_filenames)))

# lint files in chunks: each invocation of cpplint will process 16 files
Expand Down
37 changes: 17 additions & 20 deletions cpp/src/arrow/util/bpacking64_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,55 +73,52 @@ def howmanybytes(bit):


print("inline const uint8_t* unpack0_64(const uint8_t* in, uint64_t* out) {")
print(" for(int k = 0; k < {0} ; k += 1) {{".format(howmany(0)))
print(f" for(int k = 0; k < {howmany(0)} ; k += 1) {{")
print(" out[k] = 0;")
print(" }")
print(" return in;")
print("}")

for bit in range(1, 65):
print("")
print(
"inline const uint8_t* unpack{0}_64(const uint8_t* in, uint64_t* out) {{".format(bit))
print(f"inline const uint8_t* unpack{bit}_64(const uint8_t* in, uint64_t* out) {{")

if(bit < 64):
print(" const uint64_t mask = {0}ULL;".format((1 << bit)-1))
print(f" const uint64_t mask = {((1 << bit)-1)}ULL;")
maskstr = " & mask"
if (bit == 64):
maskstr = "" # no need

for k in range(howmanywords(bit)-1):
print(" uint64_t w{0} = util::SafeLoadAs<uint64_t>(in);".format(k))
print(" w{0} = arrow::BitUtil::FromLittleEndian(w{0});".format(k))
print(" in += 8;".format(k))
print(f" uint64_t w{k} = util::SafeLoadAs<uint64_t>(in);")
print(f" w{k} = arrow::BitUtil::FromLittleEndian(w{k});")
print(" in += 8;")
k = howmanywords(bit) - 1
if (bit % 2 == 0):
print(" uint64_t w{0} = util::SafeLoadAs<uint64_t>(in);".format(k))
print(" w{0} = arrow::BitUtil::FromLittleEndian(w{0});".format(k))
print(" in += 8;".format(k))
print(f" uint64_t w{k} = util::SafeLoadAs<uint64_t>(in);")
print(f" w{k} = arrow::BitUtil::FromLittleEndian(w{k});")
print(" in += 8;")
else:
print(" uint64_t w{0} = util::SafeLoadAs<uint32_t>(in);".format(k))
print(" w{0} = arrow::BitUtil::FromLittleEndian(w{0});".format(k))
print(" in += 4;".format(k))
print(f" uint64_t w{k} = util::SafeLoadAs<uint32_t>(in);")
print(f" w{k} = arrow::BitUtil::FromLittleEndian(w{k});")
print(" in += 4;")

for j in range(howmany(bit)):
firstword = j * bit // 64
secondword = (j * bit + bit - 1)//64
firstshift = (j*bit) % 64
firstshiftstr = " >> {0}".format(firstshift)
firstshiftstr = f" >> {firstshift}"
if(firstshift == 0):
firstshiftstr = "" # no need
if(firstword == secondword):
if(firstshift + bit == 64):
print(" out[{0}] = w{1}{2};".format(
j, firstword, firstshiftstr, firstshift))
print(f" out[{j}] = w{firstword}{firstshiftstr};")
else:
print(" out[{0}] = (w{1}{2}){3};".format(
j, firstword, firstshiftstr, maskstr))
print(f" out[{j}] = (w{firstword}{firstshiftstr}){maskstr};")
else:
secondshift = (64-firstshift)
print(" out[{0}] = ((w{1}{2}) | (w{3} << {4})){5};".format(
j, firstword, firstshiftstr, firstword+1, secondshift, maskstr))
print(f" out[{j}] = ((w{firstword}{firstshiftstr}) | "
f"(w{firstword+1} << {secondshift})){maskstr};")
print("")
print(" return in;")
print("}")
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/gandiva/make_precompiled_bitcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def apply_template(template, data):

if __name__ == "__main__":
if len(sys.argv) != 4:
raise ValueError("Usage: {0} <template file> <data file> "
"<output file>".format(sys.argv[0]))
raise ValueError(f"Usage: {sys.argv[0]} <template file> <data file> "
"<output file>")
with open(sys.argv[1], "rb") as f:
template = f.read()
with open(sys.argv[2], "rb") as f:
Expand Down
20 changes: 10 additions & 10 deletions dev/archery/archery/benchmark/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,30 @@

def items_per_seconds_fmt(value):
if value < 1000:
return "{} items/sec".format(value)
return f"{value} items/sec"
if value < 1000**2:
return "{:.3f}K items/sec".format(value / 1000)
return f"{value / 1000:.3f}K items/sec"
if value < 1000**3:
return "{:.3f}M items/sec".format(value / 1000**2)
return f"{value / 1000**2:.3f}M items/sec"
else:
return "{:.3f}G items/sec".format(value / 1000**3)
return f"{value / 1000**3:.3f}G items/sec"


def bytes_per_seconds_fmt(value):
if value < 1024:
return "{} bytes/sec".format(value)
return f"{value} bytes/sec"
if value < 1024**2:
return "{:.3f} KiB/sec".format(value / 1024)
return f"{value / 1024:.3f} KiB/sec"
if value < 1024**3:
return "{:.3f} MiB/sec".format(value / 1024**2)
return f"{value / 1024**2:.3f} MiB/sec"
if value < 1024**4:
return "{:.3f} GiB/sec".format(value / 1024**3)
return f"{value / 1024**3:.3f} GiB/sec"
else:
return "{:.3f} TiB/sec".format(value / 1024**4)
return f"{value / 1024**4:.3f} TiB/sec"


def change_fmt(value):
return "{:.3%}".format(value)
return f"{value:.3%}"


def formatter_for_unit(unit):
Expand Down
6 changes: 2 additions & 4 deletions dev/archery/archery/benchmark/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def value(self):
return self.median

def __repr__(self):
return "Benchmark[name={},value={}]".format(self.name, self.value)
return f"Benchmark[name={self.name},value={self.value}]"


class BenchmarkSuite:
Expand All @@ -52,6 +52,4 @@ def __init__(self, name, benchmarks):
self.benchmarks = benchmarks

def __repr__(self):
return "BenchmarkSuite[name={}, benchmarks={}]".format(
self.name, self.benchmarks
)
return f"BenchmarkSuite[name={self.name}, benchmarks={self.benchmarks}]"
4 changes: 2 additions & 2 deletions dev/archery/archery/benchmark/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__(self, benchmark_bin, benchmark_filter=None, benchmark_extras=None):
def list_benchmarks(self):
argv = ["--benchmark_list_tests"]
if self.benchmark_filter:
argv.append("--benchmark_filter={}".format(self.benchmark_filter))
argv.append(f"--benchmark_filter={self.benchmark_filter}")
result = self.run(*argv, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
return str.splitlines(result.stdout.decode("utf-8"))
Expand Down Expand Up @@ -166,7 +166,7 @@ def __init__(self, name, runs):
counters)

def __repr__(self):
return "GoogleBenchmark[name={},runs={}]".format(self.names, self.runs)
return f"GoogleBenchmark[name={self.name},runs={self.runs}]"

@classmethod
def from_json(cls, payload):
Expand Down
13 changes: 5 additions & 8 deletions dev/archery/archery/benchmark/jmh.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def __init__(self, build, benchmark_filter=None):
def list_benchmarks(self):
argv = []
if self.benchmark_filter:
argv.append("-Dbenchmark.filter={}".format(self.benchmark_filter))
argv.append(f"-Dbenchmark.filter={self.benchmark_filter}")
result = self.build.list(
*argv, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

Expand All @@ -77,13 +77,11 @@ def list_benchmarks(self):

def results(self, repetitions):
with NamedTemporaryFile(suffix=".json") as out:
argv = ["-Dbenchmark.runs={}".format(repetitions),
"-Dbenchmark.resultfile={}".format(out.name),
argv = [f"-Dbenchmark.runs={repetitions}",
f"-Dbenchmark.resultfile={out.name}",
"-Dbenchmark.resultformat=json"]
if self.benchmark_filter:
argv.append(
"-Dbenchmark.filter={}".format(self.benchmark_filter)
)
argv.append(f"-Dbenchmark.filter={self.benchmark_filter}")

self.build.benchmark(*argv, check=True)
return json.load(out)
Expand Down Expand Up @@ -187,8 +185,7 @@ def __init__(self, name, runs):
counters)

def __repr__(self):
return "JavaMicrobenchmark[name={},runs={}]".format(
self.name, self.runs)
return f"JavaMicrobenchmark[name={self.name},runs={self.runs}]"

@classmethod
def from_json(cls, payload):
Expand Down
16 changes: 7 additions & 9 deletions dev/archery/archery/benchmark/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def __init__(self, suites, **kwargs):
def list_benchmarks(self):
for suite in self._suites:
for benchmark in suite.benchmarks:
yield "{}.{}".format(suite.name, benchmark.name)
yield f"{suite.name}.{benchmark.name}"

@property
def suites(self):
Expand Down Expand Up @@ -102,7 +102,7 @@ def from_json(path_or_str, **kwargs):
return BenchmarkRunnerCodec.decode(loaded, **kwargs)

def __repr__(self):
return "BenchmarkRunner[suites={}]".format(list(self.suites))
return f"BenchmarkRunner[suites={list(self.suites)}]"


class CppBenchmarkRunner(BenchmarkRunner):
Expand Down Expand Up @@ -165,7 +165,7 @@ def list_benchmarks(self):
for suite_name, suite_bin in self.suites_binaries.items():
suite_cmd = GoogleBenchmarkCommand(suite_bin)
for benchmark_name in suite_cmd.list_benchmarks():
yield "{}.{}".format(suite_name, benchmark_name)
yield f"{suite_name}.{benchmark_name}"

@property
def suites(self):
Expand All @@ -176,16 +176,15 @@ def suites(self):
suite_and_binaries = self.suites_binaries
for suite_name in suite_and_binaries:
if not suite_matcher(suite_name):
logger.debug("Ignoring suite {}".format(suite_name))
logger.debug(f"Ignoring suite {suite_name}")
continue

suite_bin = suite_and_binaries[suite_name]
suite = self.suite(suite_name, suite_bin)

# Filter may exclude all benchmarks
if not suite:
logger.debug("Suite {} executed but no results"
.format(suite_name))
logger.debug(f"Suite {suite_name} executed but no results")
continue

suite_found = True
Expand Down Expand Up @@ -274,7 +273,7 @@ def list_benchmarks(self):
suite_cmd = JavaMicrobenchmarkHarnessCommand(self.build)
benchmark_names = suite_cmd.list_benchmarks()
for benchmark_name in benchmark_names:
yield "{}".format(benchmark_name)
yield f"{benchmark_name}"

@property
def suites(self):
Expand All @@ -284,8 +283,7 @@ def suites(self):

# Filter may exclude all benchmarks
if not suite:
logger.debug("Suite {} executed but no results"
.format(suite_name))
logger.debug(f"Suite {suite_name} executed but no results")
return

yield suite
Expand Down
6 changes: 3 additions & 3 deletions dev/archery/archery/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def __init__(self, name, handler, token=None):
self.github = github.Github(**kwargs)

def parse_command(self, payload):
mention = '@{}'.format(self.name)
mention = f'@{self.name}'
comment = payload['comment']

if payload['sender']['login'] == self.name:
Expand Down Expand Up @@ -261,7 +261,7 @@ def handle(self, event, payload):
elif event == 'pull_request_review_comment':
return self.handle_review_comment(command, payload)
else:
raise ValueError("Unexpected event type {}".format(event))
raise ValueError(f"Unexpected event type {event}")

def handle_issue_comment(self, command, payload):
repo = self.github.get_repo(payload['repository']['id'], lazy=True)
Expand Down Expand Up @@ -355,7 +355,7 @@ def _clone_arrow_and_crossbow(dest, crossbow_repo, arrow_repo_url, pr_number):
git.checkout(local_branch, git_dir=arrow_path)

# 2. clone crossbow repository
crossbow_url = 'https://github.com/{}'.format(crossbow_repo)
crossbow_url = f'https://github.com/{crossbow_repo}'
git.clone(crossbow_url, str(queue_path))

# 3. initialize crossbow objects
Expand Down
Loading
Loading