Skip to content

Commit 34337f5

Browse files
committed
Format Python code with Spotless and Black
1 parent 7d308fe commit 34337f5

35 files changed

+1664
-873
lines changed

python/examples/example.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,14 @@
1919

2020
from tsfile import ColumnSchema, TableSchema
2121
from tsfile import Tablet
22-
from tsfile import TsFileTableWriter, TsFileReader, TSDataType, TSEncoding, Compressor, ColumnCategory
22+
from tsfile import (
23+
TsFileTableWriter,
24+
TsFileReader,
25+
TSDataType,
26+
TSEncoding,
27+
Compressor,
28+
ColumnCategory,
29+
)
2330

2431
## Write
2532
table_data_dir = os.path.join(os.path.dirname(__file__), "table_data.tsfile")
@@ -36,9 +43,10 @@
3643
with TsFileTableWriter(table_data_dir, table_schema) as writer:
3744
tablet_row_num = 100
3845
tablet = Tablet(
39-
["id", "id2", "value"],
40-
[TSDataType.STRING, TSDataType.STRING, TSDataType.FLOAT],
41-
tablet_row_num)
46+
["id", "id2", "value"],
47+
[TSDataType.STRING, TSDataType.STRING, TSDataType.FLOAT],
48+
tablet_row_num,
49+
)
4250

4351
for i in range(tablet_row_num):
4452
tablet.add_timestamp(i, i * 10)
@@ -57,4 +65,3 @@
5765
print(result.get_value_by_name("id2"))
5866
print(result.get_value_by_name("value"))
5967
print(result.read_data_frame())
60-

python/pom.xml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,36 @@
3636
<build>
3737
<sourceDirectory>${project.basedir}</sourceDirectory>
3838
<plugins>
39+
<plugin>
40+
<groupId>com.diffplug.spotless</groupId>
41+
<artifactId>spotless-maven-plugin</artifactId>
42+
<version>${spotless.version}</version>
43+
<configuration>
44+
<python>
45+
<includes>
46+
<include>examples/**/*.py</include>
47+
<include>tests/**/*.py</include>
48+
<include>tsfile/**/*.py</include>
49+
<include>setup.py</include>
50+
</includes>
51+
<black>
52+
<version>24.10.0</version>
53+
<pathToExe>${project.basedir}/${python.venv.bin}black</pathToExe>
54+
</black>
55+
</python>
56+
<lineEndings>UNIX</lineEndings>
57+
<skip>${spotless.skip}</skip>
58+
</configuration>
59+
<executions>
60+
<execution>
61+
<id>spotless-check</id>
62+
<goals>
63+
<goal>check</goal>
64+
</goals>
65+
<phase>validate</phase>
66+
</execution>
67+
</executions>
68+
</plugin>
3969
<plugin>
4070
<groupId>org.codehaus.mojo</groupId>
4171
<artifactId>exec-maven-plugin</artifactId>

python/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
#
1919

2020
cython==3.0.10
21+
black==24.10.0
2122
numpy>=2.0.0,<3
2223
pandas==2.2.2
2324
setuptools==78.1.1
2425
wheel==0.46.2
2526
pyarrow>=8.0.0
26-

python/setup.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@
4141
shutil.rmtree(PKG / "include")
4242
shutil.copytree(CPP_INC, PKG / "include")
4343
if sys.platform.startswith("linux"):
44-
candidates = sorted(CPP_LIB.glob("libtsfile.so*"), key=lambda p: len(p.name), reverse=True)
44+
candidates = sorted(
45+
CPP_LIB.glob("libtsfile.so*"), key=lambda p: len(p.name), reverse=True
46+
)
4547
if not candidates:
4648
raise FileNotFoundError("missing libtsfile.so* in build output")
4749
src = candidates[0]
@@ -51,7 +53,9 @@
5153
shutil.copy2(src, link_name)
5254

5355
elif sys.platform == "darwin":
54-
candidates = sorted(CPP_LIB.glob("libtsfile.*.dylib")) or list(CPP_LIB.glob("libtsfile.dylib"))
56+
candidates = sorted(CPP_LIB.glob("libtsfile.*.dylib")) or list(
57+
CPP_LIB.glob("libtsfile.dylib")
58+
)
5559
if not candidates:
5660
raise FileNotFoundError("missing libtsfile*.dylib in build output")
5761
src = candidates[0]
@@ -61,8 +65,12 @@
6165
shutil.copy2(src, link_name)
6266
elif sys.platform == "win32":
6367
for base_name in ("libtsfile",):
64-
dll_candidates = sorted(CPP_LIB.glob(f"{base_name}*.dll"), key=lambda p: len(p.name), reverse=True)
65-
dll_a_candidates = sorted(CPP_LIB.glob(f"{base_name}*.dll.a"), key=lambda p: len(p.name), reverse=True)
68+
dll_candidates = sorted(
69+
CPP_LIB.glob(f"{base_name}*.dll"), key=lambda p: len(p.name), reverse=True
70+
)
71+
dll_a_candidates = sorted(
72+
CPP_LIB.glob(f"{base_name}*.dll.a"), key=lambda p: len(p.name), reverse=True
73+
)
6674

6775
if not dll_candidates:
6876
raise FileNotFoundError(f"missing {base_name}*.dll in build output")
@@ -119,8 +127,14 @@ def finalize_options(self):
119127
extra_link_args += ["-Wl,-rpath,@loader_path", "-stdlib=libc++"]
120128
elif sys.platform == "win32":
121129
libraries = ["tsfile"]
122-
extra_compile_args += ["-O2", "-std=c++11", "-DSIZEOF_VOID_P=8", "-D__USE_MINGW_ANSI_STDIO=1", "-DMS_WIN64",
123-
"-D_WIN64"]
130+
extra_compile_args += [
131+
"-O2",
132+
"-std=c++11",
133+
"-DSIZEOF_VOID_P=8",
134+
"-D__USE_MINGW_ANSI_STDIO=1",
135+
"-DMS_WIN64",
136+
"-D_WIN64",
137+
]
124138
extra_link_args += []
125139
else:
126140
raise RuntimeError(f"Unsupported platform: {sys.platform}")

python/tests/bench_batch_arrow_vs_dataframe.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,15 @@ def _ensure_bench_tsfile(file_path: str, row_count: int) -> None:
6161
remove(file_path)
6262
# Build data with pandas/numpy (vectorized, much faster than row-by-row Tablet)
6363
import numpy as np
64-
df = pd.DataFrame({
65-
"time": np.arange(row_count, dtype=np.int64),
66-
"device": pd.Series([f"device" for i in range(row_count)]),
67-
"value1": np.arange(0, row_count * 10, 10, dtype=np.int64),
68-
"value2": np.arange(row_count, dtype=np.float64) * 1.5,
69-
})
64+
65+
df = pd.DataFrame(
66+
{
67+
"time": np.arange(row_count, dtype=np.int64),
68+
"device": pd.Series([f"device" for i in range(row_count)]),
69+
"value1": np.arange(0, row_count * 10, 10, dtype=np.int64),
70+
"value2": np.arange(row_count, dtype=np.float64) * 1.5,
71+
}
72+
)
7073

7174
table = TableSchema(
7275
TABLE_NAME,
@@ -135,7 +138,9 @@ def _run_timed(name: str, func, *args, rounds: int = DEFAULT_TIMED_ROUNDS):
135138
avg = sum(times) / len(times)
136139
total_rows = n
137140
rows_per_sec = total_rows / avg if avg > 0 else 0
138-
print(f" {name}: {avg:.3f}s avg ({min(times):.3f}s min) rows={total_rows} {rows_per_sec:.0f} rows/s")
141+
print(
142+
f" {name}: {avg:.3f}s avg ({min(times):.3f}s min) rows={total_rows} {rows_per_sec:.0f} rows/s"
143+
)
139144
return avg, total_rows
140145

141146

@@ -148,7 +153,9 @@ def run_benchmark(
148153
_ensure_bench_tsfile(file_path, row_count)
149154
end_time = row_count + 1
150155

151-
print(f"Benchmark: {row_count} rows, batch_size={batch_size}, timed_rounds={timed_rounds}")
156+
print(
157+
f"Benchmark: {row_count} rows, batch_size={batch_size}, timed_rounds={timed_rounds}"
158+
)
152159

153160
df_avg, df_rows = _run_timed(
154161
"query_table + read_data_frame",
@@ -170,7 +177,9 @@ def run_benchmark(
170177
print()
171178
if df_avg > 0:
172179
speedup = arrow_avg / df_avg
173-
print(f" Arrow vs DataFrame time ratio: {speedup:.2f}x ({'Arrow faster' if speedup < 1 else 'DataFrame faster'})")
180+
print(
181+
f" Arrow vs DataFrame time ratio: {speedup:.2f}x ({'Arrow faster' if speedup < 1 else 'DataFrame faster'})"
182+
)
174183
assert df_rows == row_count, f"DataFrame path row count {df_rows} != {row_count}"
175184
assert arrow_rows == row_count, f"Arrow path row count {arrow_rows} != {row_count}"
176185

0 commit comments

Comments
 (0)