Skip to content

Commit a2fff56

Browse files
committed
Merge pull request #633 from petercable/mutable
Remove all mutable arguments from functions
2 parents 5d9545e + f42079c commit a2fff56

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

xray/backends/api.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,14 +312,16 @@ def open_mfdataset(paths, chunks=None, concat_dim=None, preprocess=None,
312312

313313

314314
def to_netcdf(dataset, path=None, mode='w', format=None, group=None,
315-
engine=None, writer=None, encoding={}):
315+
engine=None, writer=None, encoding=None):
316316
"""This function creates an appropriate datastore for writing a dataset to
317317
disk as a netCDF file
318318
319319
See `Dataset.to_netcdf` for full API docs.
320320
321321
The ``writer`` argument is only for the private use of save_mfdataset.
322322
"""
323+
if encoding is None:
324+
encoding = {}
323325
if path is None:
324326
path = BytesIO()
325327
if engine is None:

xray/core/coordinates.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88

99
def _coord_merge_finalize(target, other, target_conflicts, other_conflicts,
10-
promote_dims={}):
10+
promote_dims=None):
11+
if promote_dims is None:
12+
promote_dims = {}
1113
for k in target_conflicts:
1214
del target[k]
1315
for k, v in iteritems(other):

xray/core/dataset.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def _align_variables(variables, join='outer'):
8989
return new_variables
9090

9191

92-
def _expand_variables(raw_variables, old_variables={}, compat='identical'):
92+
def _expand_variables(raw_variables, old_variables=None, compat='identical'):
9393
"""Expand a dictionary of variables.
9494
9595
Returns a dictionary of Variable objects suitable for inserting into a
@@ -102,6 +102,8 @@ def _expand_variables(raw_variables, old_variables={}, compat='identical'):
102102
Raises ValueError if any conflicting values are found, between any of the
103103
new or old variables.
104104
"""
105+
if old_variables is None:
106+
old_variables = {}
105107
new_variables = OrderedDict()
106108
new_coord_names = set()
107109
variables = ChainMap(new_variables, old_variables)
@@ -329,7 +331,7 @@ def _add_missing_coords_inplace(self):
329331
coord = Coordinate(dim, data)
330332
self._variables[dim] = coord
331333

332-
def _update_vars_and_coords(self, new_variables, new_coord_names={},
334+
def _update_vars_and_coords(self, new_variables, new_coord_names=None,
333335
needs_copy=True, check_coord_names=True):
334336
"""Add a dictionary of new variables to this dataset.
335337
@@ -340,6 +342,8 @@ def _update_vars_and_coords(self, new_variables, new_coord_names={},
340342
Set `needs_copy=False` only if this dataset is brand-new and hence
341343
can be thrown away if this method fails.
342344
"""
345+
if new_coord_names is None:
346+
new_coord_names = {}
343347
# default to creating another copy of variables so can unroll if we end
344348
# up with inconsistent dimensions
345349
variables = self._variables.copy() if needs_copy else self._variables
@@ -804,8 +808,10 @@ def reset_coords(self, names=None, drop=False, inplace=False):
804808
del obj._variables[name]
805809
return obj
806810

807-
def dump_to_store(self, store, encoder=None, sync=True, encoding={}):
811+
def dump_to_store(self, store, encoder=None, sync=True, encoding=None):
808812
"""Store dataset contents to a backends.*DataStore object."""
813+
if encoding is None:
814+
encoding = {}
809815
variables, attrs = conventions.encode_dataset_coordinates(self)
810816

811817
check_encoding = set()
@@ -823,7 +829,7 @@ def dump_to_store(self, store, encoder=None, sync=True, encoding={}):
823829
store.sync()
824830

825831
def to_netcdf(self, path=None, mode='w', format=None, group=None,
826-
engine=None, encoding={}):
832+
engine=None, encoding=None):
827833
"""Write dataset contents to a netCDF file.
828834
829835
Parameters
@@ -868,6 +874,8 @@ def to_netcdf(self, path=None, mode='w', format=None, group=None,
868874
variable specific encodings as values, e.g.,
869875
``{'my_variable': {'dtype': 'int16', 'scale_factor': 0.1, 'zlib': True}, ...}``
870876
"""
877+
if encoding is None:
878+
encoding = {}
871879
from ..backends.api import to_netcdf
872880
return to_netcdf(self, path, mode, format=format, group=group,
873881
engine=engine, encoding=encoding)

0 commit comments

Comments
 (0)