Skip to content

Commit ba0f093

Browse files
committed
make _STRING_DTYPE private to try to make sphinx happy
1 parent 1e828b4 commit ba0f093

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed

src/zarr/core/metadata/v3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from zarr.core.common import ZARR_JSON, parse_named_configuration, parse_shapelike
2929
from zarr.core.config import config
3030
from zarr.core.metadata.common import ArrayMetadata, parse_attributes
31-
from zarr.core.strings import STRING_DTYPE as STRING_NP_DTYPE
31+
from zarr.core.strings import _STRING_DTYPE as STRING_NP_DTYPE
3232
from zarr.registry import get_codec_class
3333

3434
DEFAULT_DTYPE = "float64"

src/zarr/core/strings.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77

88
import numpy as np
99

10-
# STRING_DTYPE is the in-memory datatype that will be used for V3 string arrays
10+
# _STRING_DTYPE is the in-memory datatype that will be used for V3 string arrays
1111
# when reading data back from Zarr.
1212
# Any valid string-like datatype should be fine for *setting* data.
1313

14-
STRING_DTYPE: Union["np.dtypes.StringDType", "np.dtypes.ObjectDType"]
15-
NUMPY_SUPPORTS_VLEN_STRING: bool
14+
_STRING_DTYPE: Union["np.dtypes.StringDType", "np.dtypes.ObjectDType"]
15+
_NUMPY_SUPPORTS_VLEN_STRING: bool
1616

1717

1818
def cast_array(
@@ -23,24 +23,24 @@ def cast_array(
2323

2424
try:
2525
# this new vlen string dtype was added in NumPy 2.0
26-
STRING_DTYPE = np.dtypes.StringDType()
27-
NUMPY_SUPPORTS_VLEN_STRING = True
26+
_STRING_DTYPE = np.dtypes.StringDType()
27+
_NUMPY_SUPPORTS_VLEN_STRING = True
2828

2929
def cast_array(
3030
data: np.ndarray[Any, np.dtype[Any]],
3131
) -> np.ndarray[Any, np.dtypes.StringDType | np.dtypes.ObjectDType]:
32-
out = data.astype(STRING_DTYPE, copy=False)
32+
out = data.astype(_STRING_DTYPE, copy=False)
3333
return cast(np.ndarray[Any, np.dtypes.StringDType], out)
3434

3535
except AttributeError:
3636
# if not available, we fall back on an object array of strings, as in Zarr < 3
37-
STRING_DTYPE = np.dtypes.ObjectDType()
38-
NUMPY_SUPPORTS_VLEN_STRING = False
37+
_STRING_DTYPE = np.dtypes.ObjectDType()
38+
_NUMPY_SUPPORTS_VLEN_STRING = False
3939

4040
def cast_array(
4141
data: np.ndarray[Any, np.dtype[Any]],
4242
) -> np.ndarray[Any, Union["np.dtypes.StringDType", "np.dtypes.ObjectDType"]]:
43-
out = data.astype(STRING_DTYPE, copy=False)
43+
out = data.astype(_STRING_DTYPE, copy=False)
4444
return cast(np.ndarray[Any, np.dtypes.ObjectDType], out)
4545

4646

@@ -61,13 +61,13 @@ def cast_to_string_dtype(
6161
return cast_array(data)
6262
# out = data.astype(STRING_DTYPE, copy=False)
6363
# return cast(np.ndarray[Any, np.dtypes.StringDType | np.dtypes.ObjectDType], out)
64-
if NUMPY_SUPPORTS_VLEN_STRING:
65-
if np.issubdtype(data.dtype, STRING_DTYPE):
64+
if _NUMPY_SUPPORTS_VLEN_STRING:
65+
if np.issubdtype(data.dtype, _STRING_DTYPE):
6666
# already a valid string variable length string dtype
6767
return cast_array(data)
6868
if np.issubdtype(data.dtype, np.object_):
6969
# object arrays require more careful handling
70-
if NUMPY_SUPPORTS_VLEN_STRING:
70+
if _NUMPY_SUPPORTS_VLEN_STRING:
7171
try:
7272
# cast to variable-length string dtype, fail if object contains non-string data
7373
# mypy says "error: Unexpected keyword argument "coerce" for "StringDType" [call-arg]"

tests/test_strings.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,33 @@
33
import numpy as np
44
import pytest
55

6-
from zarr.core.strings import NUMPY_SUPPORTS_VLEN_STRING, STRING_DTYPE, cast_to_string_dtype
6+
from zarr.core.strings import _NUMPY_SUPPORTS_VLEN_STRING, _STRING_DTYPE, cast_to_string_dtype
77

88

99
def test_string_defaults() -> None:
10-
if NUMPY_SUPPORTS_VLEN_STRING:
11-
assert STRING_DTYPE == np.dtypes.StringDType()
10+
if _NUMPY_SUPPORTS_VLEN_STRING:
11+
assert _STRING_DTYPE == np.dtypes.StringDType()
1212
else:
13-
assert STRING_DTYPE == np.dtypes.ObjectDType()
13+
assert _STRING_DTYPE == np.dtypes.ObjectDType()
1414

1515

1616
def test_cast_to_string_dtype() -> None:
1717
d1 = np.array(["a", "b", "c"])
1818
assert d1.dtype == np.dtype("<U1")
1919
d1s = cast_to_string_dtype(d1)
20-
assert d1s.dtype == STRING_DTYPE
20+
assert d1s.dtype == _STRING_DTYPE
2121

2222
with pytest.raises(ValueError, match="Cannot cast dtype |S1"):
2323
cast_to_string_dtype(d1.astype("|S1"))
2424

25-
if NUMPY_SUPPORTS_VLEN_STRING:
26-
assert cast_to_string_dtype(d1.astype("T")).dtype == STRING_DTYPE
27-
assert cast_to_string_dtype(d1.astype("O")).dtype == STRING_DTYPE
25+
if _NUMPY_SUPPORTS_VLEN_STRING:
26+
assert cast_to_string_dtype(d1.astype("T")).dtype == _STRING_DTYPE
27+
assert cast_to_string_dtype(d1.astype("O")).dtype == _STRING_DTYPE
2828
with pytest.raises(ValueError, match="Cannot cast object dtype to string dtype"):
2929
cast_to_string_dtype(np.array([1, "b", "c"], dtype="O"))
3030
else:
3131
with pytest.warns():
32-
assert cast_to_string_dtype(d1.astype("O")).dtype == STRING_DTYPE
32+
assert cast_to_string_dtype(d1.astype("O")).dtype == _STRING_DTYPE
3333
with pytest.warns():
34-
assert cast_to_string_dtype(np.array([1, "b", "c"], dtype="O")).dtype == STRING_DTYPE
35-
assert cast_to_string_dtype(d1.astype("O"), safe=True).dtype == STRING_DTYPE
34+
assert cast_to_string_dtype(np.array([1, "b", "c"], dtype="O")).dtype == _STRING_DTYPE
35+
assert cast_to_string_dtype(d1.astype("O"), safe=True).dtype == _STRING_DTYPE

tests/v3/test_codecs/test_vlen.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
from zarr.abc.store import Store
99
from zarr.codecs import VLenBytesCodec, VLenUTF8Codec, ZstdCodec
1010
from zarr.core.metadata.v3 import ArrayV3Metadata, DataType
11-
from zarr.core.strings import NUMPY_SUPPORTS_VLEN_STRING
11+
from zarr.core.strings import _NUMPY_SUPPORTS_VLEN_STRING
1212
from zarr.storage.common import StorePath
1313

1414
numpy_str_dtypes: list[type | None] = [None, str, np.dtypes.StrDType]
1515
expected_zarr_string_dtype: np.dtype[Any]
16-
if NUMPY_SUPPORTS_VLEN_STRING:
16+
if _NUMPY_SUPPORTS_VLEN_STRING:
1717
numpy_str_dtypes.append(np.dtypes.StringDType)
1818
expected_zarr_string_dtype = np.dtypes.StringDType()
1919
else:

0 commit comments

Comments
 (0)