From b6d6dae84359dc05d7ad2ab67c150561349f418f Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Thu, 24 Jan 2019 11:12:03 -0500 Subject: [PATCH 1/7] deprecate compat & encoding --- .github/stale.yml | 3 ++- xarray/core/dataarray.py | 23 +++++++++++------------ xarray/core/dataset.py | 32 ++++++++++++++++---------------- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/.github/stale.yml b/.github/stale.yml index 099645333ec..70c580f1035 100644 --- a/.github/stale.yml +++ b/.github/stale.yml @@ -28,7 +28,8 @@ staleLabel: # Comment to post when marking as stale. Set to `false` to disable markComment: | In order to maintain a list of currently relevant issues, we mark issues as stale after a period of inactivity - If this issue remains relevant, please comment here; otherwise it will be marked as closed automatically + + If this issue remains relevant, please comment here or remove the `stale` label; otherwise it will be marked as closed automatically # Comment to post when removing the stale label. # unmarkComment: > diff --git a/xarray/core/dataarray.py b/xarray/core/dataarray.py index aa6c35394fb..c46bd843021 100644 --- a/xarray/core/dataarray.py +++ b/xarray/core/dataarray.py @@ -13,16 +13,14 @@ from .alignment import align, reindex_like_indexers from .common import AbstractArray, DataWithCoords from .coordinates import ( - DataArrayCoordinates, LevelCoordinatesSource, - assert_coordinate_consistent, remap_label_indexers) + DataArrayCoordinates, LevelCoordinatesSource, assert_coordinate_consistent, + remap_label_indexers) from .dataset import Dataset, merge_indexes, split_indexes from .formatting import format_item -from .indexes import default_indexes, Indexes +from .indexes import Indexes, default_indexes from .options import OPTIONS from .pycompat import OrderedDict, basestring, iteritems, range, zip -from .utils import ( - _check_inplace, decode_numpy_dict_values, either_dict_or_kwargs, - ensure_us_time_resolution) +from .utils import _check_inplace, either_dict_or_kwargs from .variable import ( IndexVariable, Variable, as_compatible_data, as_variable, assert_unique_multiindex_level_names) @@ -194,13 +192,14 @@ def __init__(self, data, coords=None, dims=None, name=None, attrs : dict_like or None, optional Attributes to assign to the new instance. By default, an empty attribute dictionary is initialized. - encoding : dict_like or None, optional - Dictionary specifying how to encode this array's data into a - serialized format like netCDF4. Currently used keys (for netCDF) - include '_FillValue', 'scale_factor', 'add_offset', 'dtype', - 'units' and 'calendar' (the later two only for datetime arrays). - Unrecognized keys are ignored. + encoding : deprecated """ + + if encoding is not None: + warnings.warn( + 'The `encoding` argument to `DataArray` is deprecated. ' + 'Instead, specify the encoding when writing to disk.', + FutureWarning) if fastpath: variable = data assert dims is None diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py index 3f1c038fc11..a844087704e 100644 --- a/xarray/core/dataset.py +++ b/xarray/core/dataset.py @@ -14,16 +14,16 @@ import xarray as xr from . import ( - alignment, dtypes, duck_array_ops, formatting, groupby, - indexing, ops, pdcompat, resample, rolling, utils) + alignment, dtypes, duck_array_ops, formatting, groupby, indexing, ops, + pdcompat, resample, rolling, utils) from ..coding.cftimeindex import _parse_array_of_cftime_strings from .alignment import align from .common import ( ALL_DIMS, DataWithCoords, ImplementsDatasetReduce, _contains_datetime_like_objects) from .coordinates import ( - DatasetCoordinates, LevelCoordinatesSource, - assert_coordinate_consistent, remap_label_indexers) + DatasetCoordinates, LevelCoordinatesSource, assert_coordinate_consistent, + remap_label_indexers) from .indexes import Indexes, default_indexes from .merge import ( dataset_merge_method, dataset_update_method, merge_data_and_coords, @@ -33,8 +33,8 @@ OrderedDict, basestring, dask_array_type, iteritems, range) from .utils import ( Frozen, SortedKeysDict, _check_inplace, datetime_to_numeric, - decode_numpy_dict_values, either_dict_or_kwargs, ensure_us_time_resolution, - hashable, maybe_wrap_array) + decode_numpy_dict_values, either_dict_or_kwargs, hashable, + maybe_wrap_array) from .variable import IndexVariable, Variable, as_variable, broadcast_variables # list of attributes of pd.DatetimeIndex that are ndarrays of time info @@ -322,7 +322,7 @@ class Dataset(Mapping, ImplementsDatasetReduce, DataWithCoords, _resample_cls = resample.DatasetResample def __init__(self, data_vars=None, coords=None, attrs=None, - compat='broadcast_equals'): + compat=None): """To load data from a file or file-like object, use the `open_dataset` function. @@ -346,16 +346,16 @@ def __init__(self, data_vars=None, coords=None, attrs=None, name. attrs : dict-like, optional Global attributes to save on this dataset. - compat : {'broadcast_equals', 'equals', 'identical'}, optional - String indicating how to compare variables of the same name for - potential conflicts when initializing this dataset: - - - 'broadcast_equals': all values must be equal when variables are - broadcast against each other to ensure common dimensions. - - 'equals': all values and dimensions must be the same. - - 'identical': all values, dimensions and attributes must be the - same. + compat : deprecated """ + + if compat is not None: + warnings.warn( + 'The `compat` argument to Dataset is deprecated. ' + 'Instead, use `merge` to control how variables are combined', + FutureWarning) + else: + compat = 'broadcast_equals' self._variables = OrderedDict() self._coord_names = set() self._dims = {} From 731a728533cfc37028880dd6e178c5c617c6fbea Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Tue, 29 Jan 2019 17:14:47 -0500 Subject: [PATCH 2/7] stacklevel --- xarray/core/dataarray.py | 5 +++-- xarray/core/dataset.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/xarray/core/dataarray.py b/xarray/core/dataarray.py index 4ebd1794298..1dd59aa40dd 100644 --- a/xarray/core/dataarray.py +++ b/xarray/core/dataarray.py @@ -199,8 +199,9 @@ def __init__(self, data, coords=None, dims=None, name=None, if encoding is not None: warnings.warn( 'The `encoding` argument to `DataArray` is deprecated. ' - 'Instead, specify the encoding when writing to disk.', - FutureWarning) + 'Instead, specify the encoding when writing to disk or ' + 'set the `encoding` attribute directly.', + FutureWarning, stacklevel=2) if fastpath: variable = data assert dims is None diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py index aba367a12e1..968adab4231 100644 --- a/xarray/core/dataset.py +++ b/xarray/core/dataset.py @@ -355,7 +355,7 @@ def __init__(self, data_vars=None, coords=None, attrs=None, warnings.warn( 'The `compat` argument to Dataset is deprecated. ' 'Instead, use `merge` to control how variables are combined', - FutureWarning) + FutureWarning, stacklevel=2) else: compat = 'broadcast_equals' self._variables = OrderedDict() From b079fdc5e46351870c8bf3dccfb69b4baff1d151 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Tue, 29 Jan 2019 17:18:18 -0500 Subject: [PATCH 3/7] whatsnew --- doc/whats-new.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 184cee05ae2..8ba5133345f 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -24,6 +24,10 @@ Breaking changes - Remove support for Python 2. This is the first version of xarray that is Python 3 only. (:issue:`1876`). By `Joe Hamman `_. +- The `compat` argument to `Dataset` and the `encoding` argument to + `DataArray` are deprecated and will be removed in a future release. + (:issue:`1188`) + By `Maximilian Roos `_. Enhancements ~~~~~~~~~~~~ From 0afebeb2cc5034a7752f40c6beafad977f6de75e Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Tue, 29 Jan 2019 17:42:34 -0500 Subject: [PATCH 4/7] imports --- xarray/core/dataarray.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/xarray/core/dataarray.py b/xarray/core/dataarray.py index 1dd59aa40dd..f7d2d787adf 100644 --- a/xarray/core/dataarray.py +++ b/xarray/core/dataarray.py @@ -18,10 +18,8 @@ from .formatting import format_item from .indexes import Indexes, default_indexes from .options import OPTIONS -from .pycompat import OrderedDict, basestring, iteritems, range, zip -from .utils import ( - _check_inplace, decode_numpy_dict_values, either_dict_or_kwargs, - ensure_us_time_resolution) +from .pycompat import range, zip +from .utils import _check_inplace, either_dict_or_kwargs from .variable import ( IndexVariable, Variable, as_compatible_data, as_variable, assert_unique_multiindex_level_names) From bfe9127fd607883f9a3d387b4a97d502447a569c Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Tue, 29 Jan 2019 18:12:49 -0500 Subject: [PATCH 5/7] merge conflicts --- xarray/core/dataarray.py | 1 - 1 file changed, 1 deletion(-) diff --git a/xarray/core/dataarray.py b/xarray/core/dataarray.py index f7d2d787adf..3a5dbca3de0 100644 --- a/xarray/core/dataarray.py +++ b/xarray/core/dataarray.py @@ -18,7 +18,6 @@ from .formatting import format_item from .indexes import Indexes, default_indexes from .options import OPTIONS -from .pycompat import range, zip from .utils import _check_inplace, either_dict_or_kwargs from .variable import ( IndexVariable, Variable, as_compatible_data, as_variable, From b0398e5b512ce4b4b46ec69051e4d3d9f4660944 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Tue, 29 Jan 2019 18:34:26 -0500 Subject: [PATCH 6/7] remove deprecations --- xarray/core/alignment.py | 2 +- xarray/tests/test_dataarray.py | 4 ++-- xarray/tests/test_dataset.py | 4 ---- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/xarray/core/alignment.py b/xarray/core/alignment.py index 278548cca8c..c44a0c4201d 100644 --- a/xarray/core/alignment.py +++ b/xarray/core/alignment.py @@ -495,7 +495,7 @@ def _broadcast_array(array): coords = OrderedDict(array.coords) coords.update(common_coords) return DataArray(data, coords, data.dims, name=array.name, - attrs=array.attrs, encoding=array.encoding) + attrs=array.attrs) def _broadcast_dataset(ds): data_vars = OrderedDict( diff --git a/xarray/tests/test_dataarray.py b/xarray/tests/test_dataarray.py index 59d14d7cdac..0ed853be3fe 100644 --- a/xarray/tests/test_dataarray.py +++ b/xarray/tests/test_dataarray.py @@ -258,7 +258,7 @@ def test_constructor(self): expected = Dataset({None: (['x', 'y'], data, {'bar': 2})})[None] assert_identical(expected, actual) - actual = DataArray(data, dims=['x', 'y'], encoding={'bar': 2}) + actual = DataArray(data, dims=['x', 'y']) expected = Dataset({None: (['x', 'y'], data, {}, {'bar': 2})})[None] assert_identical(expected, actual) @@ -296,7 +296,7 @@ def test_constructor_from_self_described(self): expected = DataArray(data, coords={'x': ['a', 'b'], 'y': [-1, -2]}, dims=['x', 'y'], name='foobar', - attrs={'bar': 2}, encoding={'foo': 3}) + attrs={'bar': 2}) actual = DataArray(expected) assert_identical(expected, actual) diff --git a/xarray/tests/test_dataset.py b/xarray/tests/test_dataset.py index 23a77b54356..35d77c59edd 100644 --- a/xarray/tests/test_dataset.py +++ b/xarray/tests/test_dataset.py @@ -354,13 +354,9 @@ def test_constructor_pandas_single(self): def test_constructor_compat(self): data = OrderedDict([('x', DataArray(0, coords={'y': 1})), ('y', ('z', [1, 1, 1]))]) - with pytest.raises(MergeError): - Dataset(data, compat='equals') expected = Dataset({'x': 0}, {'y': ('z', [1, 1, 1])}) actual = Dataset(data) assert_identical(expected, actual) - actual = Dataset(data, compat='broadcast_equals') - assert_identical(expected, actual) data = OrderedDict([('y', ('z', [1, 1, 1])), ('x', DataArray(0, coords={'y': 1}))]) From 69436a91a0752b3648fd831d07ade8df3a02aa1f Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Thu, 31 Jan 2019 17:05:28 -0500 Subject: [PATCH 7/7] removal date --- xarray/core/dataarray.py | 3 ++- xarray/core/dataset.py | 3 ++- xarray/tests/test_dataset.py | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/xarray/core/dataarray.py b/xarray/core/dataarray.py index 3a5dbca3de0..7d00b13a58c 100644 --- a/xarray/core/dataarray.py +++ b/xarray/core/dataarray.py @@ -195,7 +195,8 @@ def __init__(self, data, coords=None, dims=None, name=None, if encoding is not None: warnings.warn( - 'The `encoding` argument to `DataArray` is deprecated. ' + 'The `encoding` argument to `DataArray` is deprecated, and . ' + 'will be removed in 0.13. ' 'Instead, specify the encoding when writing to disk or ' 'set the `encoding` attribute directly.', FutureWarning, stacklevel=2) diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py index 968adab4231..a10a74d7799 100644 --- a/xarray/core/dataset.py +++ b/xarray/core/dataset.py @@ -353,7 +353,8 @@ def __init__(self, data_vars=None, coords=None, attrs=None, if compat is not None: warnings.warn( - 'The `compat` argument to Dataset is deprecated. ' + 'The `compat` argument to Dataset is deprecated and will be ' + 'removed in 0.13.' 'Instead, use `merge` to control how variables are combined', FutureWarning, stacklevel=2) else: diff --git a/xarray/tests/test_dataset.py b/xarray/tests/test_dataset.py index 35d77c59edd..e2e9df9dd0f 100644 --- a/xarray/tests/test_dataset.py +++ b/xarray/tests/test_dataset.py @@ -1,10 +1,10 @@ # -*- coding: utf-8 -*- +import pickle import sys import warnings from collections import OrderedDict from copy import copy, deepcopy from io import StringIO -import pickle from textwrap import dedent import numpy as np