Skip to content

Switch (some) coding/encoding in conventions.py to use xarray.coding. #1803

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 11, 2018
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 2 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ Bug fixes
with size one in some dimension can now be plotted, which is good for
exploring satellite imagery (:issue:`1780`).
By `Zac Hatfield-Dodds <https://github.com/Zac-HD>`_.
- Fixed ``UnboundLocalError`` when opening netCDF file `` (:issue:`1781`).
By `Stephan Hoyer <https://github.com/shoyer>`_.
- The ``variables``, ``attrs``, and ``dimensions`` properties have been
deprecated as part of a bug fix addressing an issue where backends were
unintentionally loading the datastores data and attributes repeatedly during
Expand Down
15 changes: 8 additions & 7 deletions xarray/backends/zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import numpy as np

from .. import coding
from .. import Variable
from ..core import indexing
from ..core.utils import FrozenOrderedDict, HiddenKeyDict
Expand Down Expand Up @@ -259,13 +260,13 @@ def encode_zarr_variable(var, needs_copy=True, name=None):
raise NotImplementedError("Variable `%s` is an object. Zarr "
"store can't yet encode objects." % name)

var = conventions.maybe_encode_datetime(var, name=name)
var = conventions.maybe_encode_timedelta(var, name=name)
var, needs_copy = conventions.maybe_encode_offset_and_scale(var,
needs_copy,
name=name)
var, needs_copy = conventions.maybe_encode_fill_value(var, needs_copy,
name=name)
for coder in [coding.times.CFDatetimeCoder(),
coding.times.CFTimedeltaCoder(),
coding.variables.CFScaleOffsetCoder(),
coding.variables.CFMaskCoder(),
coding.variables.UnsignedIntegerCoder()]:
var = coder.encode(var, name=name)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shoyer - what do you think about adding encode/decode methods to the AbstractWritableDataStore? It seems each backend handles these slightly differently but this step happens for all backends.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, some of these need to get associated with the backend classes in some way. I was waiting to do that until we finish porting all of the stuff in conventions into coding.

var = conventions.maybe_encode_nonstring_dtype(var, name=name)
var = conventions.maybe_default_fill_value(var)
var = conventions.maybe_encode_bools(var)
Expand Down
Loading