Skip to content

Commit fc8252e

Browse files
committed
Move test and add comment
1 parent 61f63df commit fc8252e

File tree

2 files changed

+22
-29
lines changed

2 files changed

+22
-29
lines changed

xarray/tests/test_backends.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5334,3 +5334,24 @@ def test_h5netcdf_entrypoint(tmp_path):
53345334
assert entrypoint.guess_can_open("something-local.nc4")
53355335
assert entrypoint.guess_can_open("something-local.cdf")
53365336
assert not entrypoint.guess_can_open("not-found-and-no-extension")
5337+
5338+
5339+
@requires_netCDF4
5340+
@pytest.mark.parametrize("str_type", (str, np.str_))
5341+
def test_write_file_from_np_str(str_type, tmpdir) -> None:
5342+
# https://github.com/pydata/xarray/pull/5264
5343+
scenarios = [str_type(v) for v in ["scenario_a", "scenario_b", "scenario_c"]]
5344+
years = range(2015, 2100 + 1)
5345+
tdf = pd.DataFrame(
5346+
data=np.random.random((len(scenarios), len(years))),
5347+
columns=years,
5348+
index=scenarios,
5349+
)
5350+
tdf.index.name = "scenario"
5351+
tdf.columns.name = "year"
5352+
tdf = tdf.stack()
5353+
tdf.name = "tas"
5354+
5355+
txr = tdf.to_xarray()
5356+
5357+
txr.to_netcdf(tmpdir.join("test.nc"))

xarray/tests/test_coding_strings.py

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
from contextlib import suppress
22

33
import numpy as np
4-
import pandas as pd
54
import pytest
65

76
from xarray import Variable
87
from xarray.coding import strings
98
from xarray.core import indexing
109

11-
from . import (
12-
IndexerMaker,
13-
assert_array_equal,
14-
assert_identical,
15-
requires_dask,
16-
requires_netCDF4,
17-
)
10+
from . import IndexerMaker, assert_array_equal, assert_identical, requires_dask
1811

1912
with suppress(ImportError):
2013
import dask.array as da
@@ -42,27 +35,6 @@ def test_numpy_subclass_handling(numpy_str_type) -> None:
4235
strings.create_vlen_dtype(numpy_str_type)
4336

4437

45-
@requires_netCDF4
46-
@pytest.mark.parametrize("str_type", (str, np.str_))
47-
def test_write_file_from_np_str(str_type) -> None:
48-
# should be moved elsewhere probably
49-
scenarios = [str_type(v) for v in ["scenario_a", "scenario_b", "scenario_c"]]
50-
years = range(2015, 2100 + 1)
51-
tdf = pd.DataFrame(
52-
data=np.random.random((len(scenarios), len(years))),
53-
columns=years,
54-
index=scenarios,
55-
)
56-
tdf.index.name = "scenario"
57-
tdf.columns.name = "year"
58-
tdf = tdf.stack()
59-
tdf.name = "tas"
60-
61-
txr = tdf.to_xarray()
62-
63-
txr.to_netcdf("test.nc")
64-
65-
6638
def test_EncodedStringCoder_decode() -> None:
6739
coder = strings.EncodedStringCoder()
6840

0 commit comments

Comments
 (0)