Skip to content

Commit 735a0d1

Browse files
committed
Make xarray io test work with larger datasets
1 parent 5a92a4f commit 735a0d1

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

test/test_xarray_io.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import sys
12
import time
23
from typing import Any, Callable, Tuple
34

@@ -12,13 +13,18 @@
1213
import flopy4.xarray_jinja.filters as filters
1314

1415
test_combinations = [
15-
(1_000, 100),
16-
(1_000_000, 1_000),
16+
# (1_000, 100),
17+
# (1_000_000, 1_000),
1718
(1_000_000, 10_000),
18-
(10_000_000, 1_000),
19+
# (10_000_000, 1_000),
1920
(10_000_000, 10_000),
20-
(100_000_000, 10_000),
21+
# (100_000_000, 10_000),
2122
(100_000_000, 100_000),
23+
(100_000_000, 1_000_000), # 1_000_000 is about 8MB of chunks.
24+
(
25+
100_000_000,
26+
10_000_000,
27+
), # 10_000_000 is about 80MB of chunks. Copilot advised 100MB.
2228
]
2329

2430

@@ -74,6 +80,7 @@ def create_and_write_jinja(tmp_path, data: xr.DataArray):
7480
"max_size,chunks",
7581
test_combinations,
7682
)
83+
@pytest.mark.skip("Too slow for large data")
7784
def test_xarray_to_text_jinja(
7885
tmp_path, max_size, chunks, time_file, memory_file
7986
):
@@ -143,6 +150,7 @@ def create_and_write_np_savetxt(tmp_path, data: xr.DataArray):
143150
"max_size,chunks",
144151
test_combinations,
145152
)
153+
@pytest.mark.skip("Too slow for large data")
146154
def test_xarray_to_text_np_savetxt(
147155
tmp_path, max_size, chunks, memory_file, time_file
148156
):
@@ -162,16 +170,24 @@ def test_xarray_to_text_np_savetxt(
162170

163171

164172
def create_and_write_extras(tmp_path, data: xr.DataArray):
173+
file_path = tmp_path / "test_xarray_to_text_extras.disu"
174+
with open(file_path, "w") as f:
175+
f.write("BEGIN GRIDDATA\n")
165176
promise = xarray_extras.csv.to_csv(
166177
data,
167-
tmp_path / "test_xarray_to_text_extras.disu",
178+
file_path,
168179
header=False,
169180
index=False,
170181
float_format="%.4f",
171182
lineterminator=" ",
172183
compression=None,
184+
mode="a",
173185
)
174186
promise.compute()
187+
# we have to open the file again,
188+
# because xarray_extras only allows paths and no file handlers.
189+
with open(file_path, "a") as f:
190+
f.write("\nEND GRIDDATA\n")
175191

176192

177193
@pytest.mark.parametrize(
@@ -193,4 +209,4 @@ def test_xarray_to_text_extras(
193209

194210
with open(tmp_path / "test_xarray_to_text_extras.disu", "r") as f:
195211
output = f.readlines()
196-
assert len(output) == 1
212+
assert len(output) == 3

0 commit comments

Comments
 (0)