Skip to content

Commit d634f64

Browse files
authored
deprecate compat & encoding (#2703)
* deprecate compat & encoding * stacklevel * whatsnew * imports * merge conflicts * remove deprecations * removal date
1 parent 4923039 commit d634f64

File tree

7 files changed

+40
-37
lines changed

7 files changed

+40
-37
lines changed

.github/stale.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ staleLabel: stale
2828
# Comment to post when marking as stale. Set to `false` to disable
2929
markComment: |
3030
In order to maintain a list of currently relevant issues, we mark issues as stale after a period of inactivity
31-
If this issue remains relevant, please comment here; otherwise it will be marked as closed automatically
31+
32+
If this issue remains relevant, please comment here or remove the `stale` label; otherwise it will be marked as closed automatically
3233
3334
# Comment to post when removing the stale label.
3435
# unmarkComment: >

doc/whats-new.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ Breaking changes
2424
- Remove support for Python 2. This is the first version of xarray that is
2525
Python 3 only. (:issue:`1876`).
2626
By `Joe Hamman <https://github.com/jhamman>`_.
27+
- The `compat` argument to `Dataset` and the `encoding` argument to
28+
`DataArray` are deprecated and will be removed in a future release.
29+
(:issue:`1188`)
30+
By `Maximilian Roos <https://github.com/max-sixty>`_.
2731

2832
Enhancements
2933
~~~~~~~~~~~~

xarray/core/alignment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ def _broadcast_array(array):
495495
coords = OrderedDict(array.coords)
496496
coords.update(common_coords)
497497
return DataArray(data, coords, data.dims, name=array.name,
498-
attrs=array.attrs, encoding=array.encoding)
498+
attrs=array.attrs)
499499

500500
def _broadcast_dataset(ds):
501501
data_vars = OrderedDict(

xarray/core/dataarray.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@
1212
from .alignment import align, reindex_like_indexers
1313
from .common import AbstractArray, DataWithCoords
1414
from .coordinates import (
15-
DataArrayCoordinates, LevelCoordinatesSource,
16-
assert_coordinate_consistent, remap_label_indexers)
15+
DataArrayCoordinates, LevelCoordinatesSource, assert_coordinate_consistent,
16+
remap_label_indexers)
1717
from .dataset import Dataset, merge_indexes, split_indexes
1818
from .formatting import format_item
19-
from .indexes import default_indexes, Indexes
19+
from .indexes import Indexes, default_indexes
2020
from .options import OPTIONS
21-
from .utils import (
22-
_check_inplace, decode_numpy_dict_values, either_dict_or_kwargs,
23-
ensure_us_time_resolution)
21+
from .utils import _check_inplace, either_dict_or_kwargs
2422
from .variable import (
2523
IndexVariable, Variable, as_compatible_data, as_variable,
2624
assert_unique_multiindex_level_names)
@@ -192,13 +190,16 @@ def __init__(self, data, coords=None, dims=None, name=None,
192190
attrs : dict_like or None, optional
193191
Attributes to assign to the new instance. By default, an empty
194192
attribute dictionary is initialized.
195-
encoding : dict_like or None, optional
196-
Dictionary specifying how to encode this array's data into a
197-
serialized format like netCDF4. Currently used keys (for netCDF)
198-
include '_FillValue', 'scale_factor', 'add_offset', 'dtype',
199-
'units' and 'calendar' (the later two only for datetime arrays).
200-
Unrecognized keys are ignored.
193+
encoding : deprecated
201194
"""
195+
196+
if encoding is not None:
197+
warnings.warn(
198+
'The `encoding` argument to `DataArray` is deprecated, and . '
199+
'will be removed in 0.13. '
200+
'Instead, specify the encoding when writing to disk or '
201+
'set the `encoding` attribute directly.',
202+
FutureWarning, stacklevel=2)
202203
if fastpath:
203204
variable = data
204205
assert dims is None

xarray/core/dataset.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313
import xarray as xr
1414

1515
from . import (
16-
alignment, dtypes, duck_array_ops, formatting, groupby,
17-
indexing, ops, pdcompat, resample, rolling, utils)
16+
alignment, dtypes, duck_array_ops, formatting, groupby, indexing, ops,
17+
pdcompat, resample, rolling, utils)
1818
from ..coding.cftimeindex import _parse_array_of_cftime_strings
1919
from .alignment import align
2020
from .common import (
2121
ALL_DIMS, DataWithCoords, ImplementsDatasetReduce,
2222
_contains_datetime_like_objects)
2323
from .coordinates import (
24-
DatasetCoordinates, LevelCoordinatesSource,
25-
assert_coordinate_consistent, remap_label_indexers)
24+
DatasetCoordinates, LevelCoordinatesSource, assert_coordinate_consistent,
25+
remap_label_indexers)
2626
from .indexes import Indexes, default_indexes
2727
from .merge import (
2828
dataset_merge_method, dataset_update_method, merge_data_and_coords,
@@ -31,8 +31,8 @@
3131
from .pycompat import dask_array_type
3232
from .utils import (
3333
Frozen, SortedKeysDict, _check_inplace, datetime_to_numeric,
34-
decode_numpy_dict_values, either_dict_or_kwargs, ensure_us_time_resolution,
35-
hashable, maybe_wrap_array)
34+
decode_numpy_dict_values, either_dict_or_kwargs, hashable,
35+
maybe_wrap_array)
3636
from .variable import IndexVariable, Variable, as_variable, broadcast_variables
3737

3838
# list of attributes of pd.DatetimeIndex that are ndarrays of time info
@@ -324,7 +324,7 @@ class Dataset(Mapping, ImplementsDatasetReduce, DataWithCoords):
324324
_resample_cls = resample.DatasetResample
325325

326326
def __init__(self, data_vars=None, coords=None, attrs=None,
327-
compat='broadcast_equals'):
327+
compat=None):
328328
"""To load data from a file or file-like object, use the `open_dataset`
329329
function.
330330
@@ -348,16 +348,17 @@ def __init__(self, data_vars=None, coords=None, attrs=None,
348348
name.
349349
attrs : dict-like, optional
350350
Global attributes to save on this dataset.
351-
compat : {'broadcast_equals', 'equals', 'identical'}, optional
352-
String indicating how to compare variables of the same name for
353-
potential conflicts when initializing this dataset:
354-
355-
- 'broadcast_equals': all values must be equal when variables are
356-
broadcast against each other to ensure common dimensions.
357-
- 'equals': all values and dimensions must be the same.
358-
- 'identical': all values, dimensions and attributes must be the
359-
same.
351+
compat : deprecated
360352
"""
353+
354+
if compat is not None:
355+
warnings.warn(
356+
'The `compat` argument to Dataset is deprecated and will be '
357+
'removed in 0.13.'
358+
'Instead, use `merge` to control how variables are combined',
359+
FutureWarning, stacklevel=2)
360+
else:
361+
compat = 'broadcast_equals'
361362
self._variables = OrderedDict()
362363
self._coord_names = set()
363364
self._dims = {}

xarray/tests/test_dataarray.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ def test_constructor(self):
258258
expected = Dataset({None: (['x', 'y'], data, {'bar': 2})})[None]
259259
assert_identical(expected, actual)
260260

261-
actual = DataArray(data, dims=['x', 'y'], encoding={'bar': 2})
261+
actual = DataArray(data, dims=['x', 'y'])
262262
expected = Dataset({None: (['x', 'y'], data, {}, {'bar': 2})})[None]
263263
assert_identical(expected, actual)
264264

@@ -296,7 +296,7 @@ def test_constructor_from_self_described(self):
296296
expected = DataArray(data,
297297
coords={'x': ['a', 'b'], 'y': [-1, -2]},
298298
dims=['x', 'y'], name='foobar',
299-
attrs={'bar': 2}, encoding={'foo': 3})
299+
attrs={'bar': 2})
300300
actual = DataArray(expected)
301301
assert_identical(expected, actual)
302302

xarray/tests/test_dataset.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# -*- coding: utf-8 -*-
2+
import pickle
23
import sys
34
import warnings
45
from collections import OrderedDict
56
from copy import copy, deepcopy
67
from io import StringIO
7-
import pickle
88
from textwrap import dedent
99

1010
import numpy as np
@@ -354,13 +354,9 @@ def test_constructor_pandas_single(self):
354354
def test_constructor_compat(self):
355355
data = OrderedDict([('x', DataArray(0, coords={'y': 1})),
356356
('y', ('z', [1, 1, 1]))])
357-
with pytest.raises(MergeError):
358-
Dataset(data, compat='equals')
359357
expected = Dataset({'x': 0}, {'y': ('z', [1, 1, 1])})
360358
actual = Dataset(data)
361359
assert_identical(expected, actual)
362-
actual = Dataset(data, compat='broadcast_equals')
363-
assert_identical(expected, actual)
364360

365361
data = OrderedDict([('y', ('z', [1, 1, 1])),
366362
('x', DataArray(0, coords={'y': 1}))])

0 commit comments

Comments
 (0)