Skip to content

Commit 2cde4e5

Browse files
authored
fix: perf_tests scripts to use pyarrow or LazyArrowStreamTable (#111)
Found a couple bugs after recent changes while familiarizing myself with the code.
1 parent 43a447f commit 2cde4e5

5 files changed

Lines changed: 28 additions & 30 deletions

File tree

perf_tests/compute_air.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#!/usr/bin/env python3
22

33
import xarray as xr
4-
import xarray_sql as qr
4+
import xarray_sql as xql
55

66
if __name__ == "__main__":
77
air = xr.tutorial.open_dataset("air_temperature")
88
chunks = {"time": 240}
99
air = air.chunk(chunks)
1010

11-
df = qr.read_xarray(air).compute()
11+
df = xql.read_xarray(air).read_pandas()
1212

1313
print(len(df))

perf_tests/groupby_air.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/usr/bin/env python3
22

3+
from datafusion import SessionContext
34
import xarray as xr
4-
import xarray_sql as qr
5-
from dask_sql import Context
5+
import xarray_sql as xql
66

77

88
if __name__ == "__main__":
@@ -13,12 +13,12 @@
1313
time=slice(0, 12), lat=slice(0, 11), lon=slice(0, 10)
1414
).chunk(chunks)
1515

16-
df = qr.read_xarray(air_small)
16+
df = xql.read_xarray_table(air_small)
1717

18-
c = Context()
19-
c.create_table("air", df)
18+
ctx = SessionContext()
19+
ctx.register_table("air", df)
2020

21-
query = c.sql(
21+
query = ctx.sql(
2222
"""
2323
SELECT
2424
"lat", "lon", SUM("air") as air_total
@@ -29,10 +29,9 @@
2929
"""
3030
)
3131

32-
result = query.compute()
32+
result = query.collect()
3333

34-
expected = air_small.dims["lat"] * air_small.dims["lon"]
35-
assert (
36-
len(result) == expected
37-
), f"Length must be {expected}, but was {len(result)}."
34+
expected = air_small.sizes["lat"] * air_small.sizes["lon"]
35+
actual = sum(len(batch) for batch in result)
36+
assert actual == expected, f"Length must be {expected}, but was {actual}."
3837
print(expected)

perf_tests/groupby_air_full.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
#!/usr/bin/env python3
22

33
import xarray as xr
4-
import xarray_sql as qr
5-
from dask_sql import Context
6-
4+
import xarray_sql as xql
5+
from datafusion import SessionContext
76

87
if __name__ == "__main__":
98
air = xr.tutorial.open_dataset("air_temperature")
109
chunks = {"time": 240}
1110
air = air.chunk(chunks)
1211

13-
df = qr.read_xarray(air)
12+
df = xql.read_xarray_table(air)
1413

15-
c = Context()
16-
c.create_table("air", df)
14+
ctx = SessionContext()
15+
ctx.register_table("air", df)
1716

18-
query = c.sql(
17+
query = ctx.sql(
1918
"""
2019
SELECT
2120
"lat", "lon", SUM("air") as air_total
@@ -26,10 +25,10 @@
2625
"""
2726
)
2827

29-
result = query.compute()
28+
result = query.collect()
29+
30+
expected = air.sizes["lat"] * air.sizes["lon"]
31+
actual = sum(len(batch) for batch in result)
3032

31-
expected = air.dims["lat"] * air.dims["lon"]
32-
assert (
33-
len(result) == expected
34-
), f"Length must be {expected}, but was {len(result)}."
33+
assert actual == expected, f"Length must be {expected}, but was {actual}."
3534
print(expected)

perf_tests/open_era5.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#!/usr/bin/env python3
22

33
import xarray as xr
4-
import xarray_sql as qr
4+
import xarray_sql as xql
55

66
# Requires authenticating with GCP
77
era5_ds = xr.open_zarr(
88
"gs://gcp-public-data-arco-era5/ar/1959-2022-full_37-1h-0p25deg-chunk-1.zarr-v2",
99
chunks={"time": 240, "level": 1},
1010
)
11-
era5_wind_df = qr.read_xarray(
11+
era5_wind_df = xql.read_xarray(
1212
era5_ds[["u_component_of_wind", "v_component_of_wind"]]
1313
)
1414

15-
print(era5_wind_df.columns)
15+
print(era5_wind_df.schema)

perf_tests/sanity.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python3
22

33
import xarray as xr
4-
import xarray_sql as qr
4+
import xarray_sql as xql
55

66
if __name__ == "__main__":
77
air = xr.tutorial.open_dataset("air_temperature")
@@ -11,6 +11,6 @@
1111
time=slice(0, 12), lat=slice(0, 11), lon=slice(0, 10)
1212
).chunk(chunks)
1313

14-
df = qr.read_xarray(air_small).compute()
14+
df = xql.read_xarray(air_small).read_pandas()
1515

1616
print(len(df))

0 commit comments

Comments
 (0)