Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ repos:
- id: rst-inline-touching-normal
- id: text-unicode-replacement-char
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.4
rev: v0.15.9
hooks:
- id: ruff-check
args: ["--fix", "--show-fixes"]
Expand All @@ -42,7 +42,7 @@ repos:
- id: prettier
args: ["--cache-location=.prettier_cache/cache"]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.19.1
rev: v1.20.0
hooks:
- id: mypy
# Copied from setup.cfg
Expand Down Expand Up @@ -76,7 +76,7 @@ repos:
- id: validate-pyproject
additional_dependencies: ["validate-pyproject-schema-store[all]"]
- repo: https://github.com/adhtruong/mirrors-typos
rev: v1.44.0
rev: v1.45.0
hooks:
- id: typos
- repo: https://github.com/zizmorcore/zizmor-pre-commit
Expand Down
4 changes: 2 additions & 2 deletions xarray/backends/writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
T_DataTreeNetcdfTypes = Literal["NETCDF4"]


WRITEABLE_STORES: dict[T_NetcdfEngine, Callable] = {
WRITABLE_STORES: dict[T_NetcdfEngine, Callable] = {
"netcdf4": backends.NetCDF4DataStore.open,
"scipy": backends.ScipyDataStore,
"h5netcdf": backends.H5NetCDFStore.open,
Expand All @@ -57,7 +57,7 @@ def get_writable_netcdf_store(
) -> AbstractWritableDataStore:
"""Create a store for writing to a netCDF file."""
try:
store_open = WRITEABLE_STORES[engine]
store_open = WRITABLE_STORES[engine]
except KeyError as err:
raise ValueError(f"unrecognized engine for to_netcdf: {engine!r}") from err

Expand Down
2 changes: 1 addition & 1 deletion xarray/compat/dask_array_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def sliding_window_view(
x, window_shape, axis=None, *, automatic_rechunk=True, **kwargs
):
# Backcompat for handling `automatic_rechunk`, delete when dask>=2024.11.0
# Note that subok, writeable are unsupported by dask, so we ignore those in kwargs
# Note that subok, writable are unsupported by dask, so we ignore those in kwargs
from dask.array.lib.stride_tricks import sliding_window_view

if module_available("dask", "2024.11.0"):
Expand Down
8 changes: 4 additions & 4 deletions xarray/computation/rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,8 @@ def construct(
Returns
-------
DataArray
a view of the original array. By default, the returned array is not writeable.
For numpy arrays, one can pass ``writeable=True`` in ``sliding_window_view_kwargs``.
a view of the original array. By default, the returned array is not writable.
For numpy arrays, one can pass ``writable=True`` in ``sliding_window_view_kwargs``.

See Also
--------
Expand Down Expand Up @@ -954,8 +954,8 @@ def construct(
Returns
-------
Dataset
Dataset with views of the original arrays. By default, the returned arrays are not writeable.
For numpy arrays, one can pass ``writeable=True`` in ``sliding_window_view_kwargs``.
Dataset with views of the original arrays. By default, the returned arrays are not writable.
For numpy arrays, one can pass ``writable=True`` in ``sliding_window_view_kwargs``.

See Also
--------
Expand Down
2 changes: 1 addition & 1 deletion xarray/core/duck_array_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def sliding_window_view(array, window_shape, axis=None, **kwargs):
eager_module=xp.lib.stride_tricks,
dask_module=dask_array_compat,
dask_only_kwargs=("automatic_rechunk",),
numpy_only_kwargs=("subok", "writeable"),
numpy_only_kwargs=("subok", "writable"),
)
return func(array, window_shape, axis=axis, **kwargs)

Expand Down
2 changes: 1 addition & 1 deletion xarray/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1720,7 +1720,7 @@ def _safe_setitem(self, array, key: tuple[Any, ...], value: Any) -> None:
array[key] = value
except ValueError as exc:
# More informative exception if read-only view
if not array.flags.writeable and not array.flags.owndata:
if not array.flags.writable and not array.flags.owndata:
raise ValueError(
"Assignment destination is a view. "
"Do you want to .copy() array first?"
Expand Down
6 changes: 3 additions & 3 deletions xarray/core/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,10 @@ def _possibly_convert_objects(values):
"""
as_series = pd.Series(values.ravel(), copy=False)
result = np.asarray(as_series).reshape(values.shape)
if not result.flags.writeable:
if not result.flags.writable:
# GH8843, pandas copy-on-write mode creates read-only arrays by default
try:
result.flags.writeable = True
result.flags.writable = True
except ValueError:
result = result.copy()
# For why we need this behavior: https://github.com/pandas-dev/pandas/issues/61938
Expand Down Expand Up @@ -1479,7 +1479,7 @@ def set_dims(self, dim, shape=None):

if self.dims == expanded_dims:
# don't use broadcast_to unless necessary so the result remains
# writeable if possible
# writable if possible
expanded_data = self._data
elif shape is None or all(
s == 1 for s, e in zip(shape, dim, strict=True) if e not in self_dims
Expand Down
6 changes: 3 additions & 3 deletions xarray/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@
)


def assert_writeable(ds):
def assert_writable(ds):
readonly = [
name
for name, var in ds.variables.items()
if not isinstance(var, IndexVariable)
and not isinstance(
var.data, PandasExtensionArray | pd.api.extensions.ExtensionArray
)
and not var.data.flags.writeable
and not var.data.flags.writable
]
assert not readonly, readonly

Expand Down Expand Up @@ -439,7 +439,7 @@ def create_test_data(
numbers_values = rs.integers(0, 3, _dims["dim3"], dtype="int64")
obj.coords["numbers"] = ("dim3", numbers_values)
obj.encoding = {"foo": "bar"}
assert_writeable(obj)
assert_writable(obj)
return obj


Expand Down
12 changes: 6 additions & 6 deletions xarray/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
assert_equal,
assert_identical,
assert_no_warnings,
assert_writeable,
assert_writable,
create_test_data,
has_cftime,
has_dask,
Expand Down Expand Up @@ -163,9 +163,9 @@ def create_append_test_data(seed=None) -> tuple[Dataset, Dataset, Dataset]:
}
)

assert_writeable(ds)
assert_writeable(ds_to_append)
assert_writeable(ds_with_new_var)
assert_writable(ds)
assert_writable(ds_to_append)
assert_writable(ds_with_new_var)
return ds, ds_to_append, ds_with_new_var


Expand All @@ -178,8 +178,8 @@ def make_datasets(data, data_to_append) -> tuple[Dataset, Dataset]:
ds_to_append = xr.Dataset(
{"temperature": (["time"], data_to_append)}, coords={"time": [0, 1, 2]}
)
assert_writeable(ds)
assert_writeable(ds_to_append)
assert_writable(ds)
assert_writable(ds_to_append)
return ds, ds_to_append

u2_strings = ["ab", "cd", "ef"]
Expand Down
4 changes: 2 additions & 2 deletions xarray/tests/test_rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,13 +630,13 @@ def test_rolling_construct_automatic_rechunk(self):
rechunked = obj.rolling(time=100, center=True).construct(
"window",
sliding_window_view_kwargs=dict(
automatic_rechunk=True, writeable=False
automatic_rechunk=True, writable=False
),
)
not_rechunked = obj.rolling(time=100, center=True).construct(
"window",
sliding_window_view_kwargs=dict(
automatic_rechunk=False, writeable=True
automatic_rechunk=False, writable=True
),
)
assert rechunked.chunksizes != not_rechunked.chunksizes
Expand Down
8 changes: 4 additions & 4 deletions xarray/tests/test_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ def var():
np.array(["2019-01-01", "2019-01-02", "2019-01-03"], dtype="datetime64[ns]"),
],
)
def test_as_compatible_data_writeable(data):
def test_as_compatible_data_writable(data):
# In pandas 3 the mode.copy_on_write option defaults to True, so the option
# setting logic can be removed once our minimum version of pandas is
# greater than or equal to 3.
if not has_pandas_3:
pd.set_option("mode.copy_on_write", True)
# GH8843, ensure writeable arrays for data_vars even with
# GH8843, ensure writable arrays for data_vars even with
# pandas copy-on-write mode
assert as_compatible_data(data).flags.writeable
assert as_compatible_data(data).flags.writable
if not has_pandas_3:
pd.reset_option("mode.copy_on_write")

Expand Down Expand Up @@ -2767,7 +2767,7 @@ def test_masked_array(self):
assert np.dtype(float) == actual.dtype

original2: Any = np.ma.MaskedArray([1.0, 2.0], mask=[True, False])
original2.flags.writeable = False
original2.flags.writable = False
expected2: Any = [np.nan, 2.0]
actual = as_compatible_data(original2)
assert_array_equal(expected2, actual)
Expand Down
Loading