How to use the descarteslabs.common.workflows.unmarshal.register function in descarteslabs

To help you get started, we’ve selected a few descarteslabs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github descarteslabs / descarteslabs-python / descarteslabs / workflows / containers / containers.py View on Github external
def __eq__(self, other):
        return isinstance(other, type(self)) and self.features == other.features

    def __ne__(self, other):
        return not self.__eq__(other)

    def __iter__(self):
        return iter(self.features)

    def __len__(self):
        return len(self.features)


unmarshal.register("Geometry", unmarshal.unpack_into(Geometry))
unmarshal.register("GeometryCollection", unmarshal.unpack_into(GeometryCollection))
unmarshal.register(
    "Feature", lambda geojson: Feature(geojson["geometry"], geojson["properties"])
)
unmarshal.register(
    "FeatureCollection", lambda geojson: FeatureCollection(geojson["features"])
)
github descarteslabs / descarteslabs-python / descarteslabs / workflows / containers / containers.py View on Github external
}

    def __eq__(self, other):
        return isinstance(other, type(self)) and self.features == other.features

    def __ne__(self, other):
        return not self.__eq__(other)

    def __iter__(self):
        return iter(self.features)

    def __len__(self):
        return len(self.features)


unmarshal.register("Geometry", unmarshal.unpack_into(Geometry))
unmarshal.register("GeometryCollection", unmarshal.unpack_into(GeometryCollection))
unmarshal.register(
    "Feature", lambda geojson: Feature(geojson["geometry"], geojson["properties"])
)
unmarshal.register(
    "FeatureCollection", lambda geojson: FeatureCollection(geojson["features"])
)
github descarteslabs / descarteslabs-python / descarteslabs / workflows / results / results.py View on Github external
import six
import numpy as np

from descarteslabs.common.workflows import unmarshal


unmarshal.register("Number", unmarshal.identity)
unmarshal.register("Int", unmarshal.identity)
unmarshal.register("Float", unmarshal.identity)
unmarshal.register("NoneType", unmarshal.identity)
unmarshal.register("Bool", unmarshal.astype(bool))
unmarshal.register("Str", unmarshal.astype(str))
# ^ TODO(gabe): on py2 these should possibly be unicode
unmarshal.register("List", unmarshal.astype(list))
unmarshal.register("Tuple", unmarshal.astype(tuple))
unmarshal.register("Dict", unmarshal.astype(dict))
unmarshal.register("KnownDict", unmarshal.astype(dict))
unmarshal.register("AOI", unmarshal.astype(dict))
unmarshal.register("DLTile", unmarshal.astype(dict))
unmarshal.register("XYZTile", unmarshal.astype(dict))
unmarshal.register("GeoContext", unmarshal.astype(dict))


def datetime_from_string(s):
    try:
        return datetime.datetime.fromisoformat(s)
    except AttributeError:
        raise TypeError(
            "Datetime unmarshalling failed. If you are using PY2, update to PY3 to fix this error."
        )
github descarteslabs / descarteslabs-python / descarteslabs / workflows / containers / containers.py View on Github external
def datetime_from_string(s):
    try:
        return datetime.datetime.fromisoformat(s)
    except AttributeError:
        raise TypeError(
            "Datetime unmarshalling failed. If you are using PY2, update to PY3 to fix this error."
        )


def timedelta_from_seconds(s):
    return datetime.timedelta(seconds=s)


unmarshal.register("Datetime", datetime_from_string)
unmarshal.register("Timedelta", timedelta_from_seconds)


class EqualityMixin(object):
    def __eq__(self, other):
        if not isinstance(other, type(self)):
            return False
        try:
            np.testing.assert_equal(self.__dict__, other.__dict__)
        except AssertionError:
            return False
        else:
            return True


class Image(EqualityMixin):
    def __init__(self, ndarray, properties, bandinfo):
github descarteslabs / descarteslabs-python / descarteslabs / workflows / containers / containers.py View on Github external
import numpy as np
import datetime

import collections

from descarteslabs.common.workflows import unmarshal


unmarshal.register("Number", unmarshal.identity)
unmarshal.register("Int", unmarshal.identity)
unmarshal.register("Float", unmarshal.identity)
unmarshal.register("NoneType", unmarshal.identity)
unmarshal.register("Bool", unmarshal.astype(bool))
unmarshal.register("String", unmarshal.astype(str))
unmarshal.register("Str", unmarshal.astype(str))
# ^ TODO(gabe): on py2 these should possibly be unicode
# ^ TODO(gabe): remove "String" once old client is deprecated
unmarshal.register("List", unmarshal.astype(list))
unmarshal.register("Tuple", unmarshal.astype(tuple))
unmarshal.register("Dict", unmarshal.astype(dict))
unmarshal.register("AOI", unmarshal.astype(dict))
unmarshal.register("DLTile", unmarshal.astype(dict))
unmarshal.register("XYZTile", unmarshal.astype(dict))


def datetime_from_string(s):
    try:
        return datetime.datetime.fromisoformat(s)
github descarteslabs / descarteslabs-python / descarteslabs / workflows / results / results.py View on Github external
def datetime_from_string(s):
    try:
        return datetime.datetime.fromisoformat(s)
    except AttributeError:
        raise TypeError(
            "Datetime unmarshalling failed. If you are using PY2, update to PY3 to fix this error."
        )


def timedelta_from_seconds(s):
    return datetime.timedelta(seconds=s)


unmarshal.register("Datetime", datetime_from_string)
unmarshal.register("Timedelta", timedelta_from_seconds)


def warn_on_old_python_wrapper(unmarshal_func):
    @functools.wraps(unmarshal_func)
    def unmarshaler(*args, **kwargs):
        if sys.version_info[:2] < (3, 6):
            warnings.warn(
                "Using Python version < 3.6 will result in a nondeterministic ordering "
                "of bandinfos for `Image` and `ImageCollection`. "
                "Update to Python 3.6 or greater to fix this.",
                RuntimeWarning,
            )
        return unmarshal_func(*args, **kwargs)

    return unmarshaler
github descarteslabs / descarteslabs-python / descarteslabs / workflows / results / results.py View on Github external
def __iter__(self):
        return iter(self.features)

    def __len__(self):
        return len(self.features)

    def __repr__(self):
        return "{}(features={})".format(type(self).__name__, self.features)


unmarshal.register("Geometry", unmarshal.unpack_into(GeometryResult))
unmarshal.register(
    "GeometryCollection", unmarshal.unpack_into(GeometryCollectionResult)
)
unmarshal.register(
    "Feature", lambda geojson: FeatureResult(geojson["geometry"], geojson["properties"])
)
unmarshal.register(
    "FeatureCollection", lambda geojson: FeatureCollectionResult(geojson["features"])
)
github descarteslabs / descarteslabs-python / descarteslabs / workflows / containers / containers.py View on Github external
def __ne__(self, other):
        return not self.__eq__(other)

    def __iter__(self):
        return iter(self.features)

    def __len__(self):
        return len(self.features)


unmarshal.register("Geometry", unmarshal.unpack_into(Geometry))
unmarshal.register("GeometryCollection", unmarshal.unpack_into(GeometryCollection))
unmarshal.register(
    "Feature", lambda geojson: Feature(geojson["geometry"], geojson["properties"])
)
unmarshal.register(
    "FeatureCollection", lambda geojson: FeatureCollection(geojson["features"])
)
github descarteslabs / descarteslabs-python / descarteslabs / workflows / results / results.py View on Github external
unmarshal.register("Number", unmarshal.identity)
unmarshal.register("Int", unmarshal.identity)
unmarshal.register("Float", unmarshal.identity)
unmarshal.register("NoneType", unmarshal.identity)
unmarshal.register("Bool", unmarshal.astype(bool))
unmarshal.register("Str", unmarshal.astype(str))
# ^ TODO(gabe): on py2 these should possibly be unicode
unmarshal.register("List", unmarshal.astype(list))
unmarshal.register("Tuple", unmarshal.astype(tuple))
unmarshal.register("Dict", unmarshal.astype(dict))
unmarshal.register("KnownDict", unmarshal.astype(dict))
unmarshal.register("AOI", unmarshal.astype(dict))
unmarshal.register("DLTile", unmarshal.astype(dict))
unmarshal.register("XYZTile", unmarshal.astype(dict))
unmarshal.register("GeoContext", unmarshal.astype(dict))


def datetime_from_string(s):
    try:
        return datetime.datetime.fromisoformat(s)
    except AttributeError:
        raise TypeError(
            "Datetime unmarshalling failed. If you are using PY2, update to PY3 to fix this error."
        )


def timedelta_from_seconds(s):
    return datetime.timedelta(seconds=s)


unmarshal.register("Datetime", datetime_from_string)
github descarteslabs / descarteslabs-python / descarteslabs / workflows / results / results.py View on Github external
import functools

import six
import numpy as np

from descarteslabs.common.workflows import unmarshal


unmarshal.register("Number", unmarshal.identity)
unmarshal.register("Int", unmarshal.identity)
unmarshal.register("Float", unmarshal.identity)
unmarshal.register("NoneType", unmarshal.identity)
unmarshal.register("Bool", unmarshal.astype(bool))
unmarshal.register("Str", unmarshal.astype(str))
# ^ TODO(gabe): on py2 these should possibly be unicode
unmarshal.register("List", unmarshal.astype(list))
unmarshal.register("Tuple", unmarshal.astype(tuple))
unmarshal.register("Dict", unmarshal.astype(dict))
unmarshal.register("KnownDict", unmarshal.astype(dict))
unmarshal.register("AOI", unmarshal.astype(dict))
unmarshal.register("DLTile", unmarshal.astype(dict))
unmarshal.register("XYZTile", unmarshal.astype(dict))
unmarshal.register("GeoContext", unmarshal.astype(dict))


def datetime_from_string(s):
    try:
        return datetime.datetime.fromisoformat(s)
    except AttributeError:
        raise TypeError(
            "Datetime unmarshalling failed. If you are using PY2, update to PY3 to fix this error."
        )