Skip to content
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

Fix string enum serialization #654

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- `generate_subcatalogs` can include multiple template values in a single subfolder layer
([#595](https://github.com/stac-utils/pystac/pull/595))
- Avoid implicit re-exports ([#591](https://github.com/stac-utils/pystac/pull/591))
- Regression where string `Enum` values were not serialized properly in methods like `Link.to_dict` ([#654](https://github.com/stac-utils/pystac/pull/654))

### Deprecated

Expand Down
10 changes: 7 additions & 3 deletions pystac/catalog.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
from copy import deepcopy
from enum import Enum
from pystac.errors import STACTypeError
from typing import (
Any,
Expand Down Expand Up @@ -29,15 +28,20 @@
identify_stac_object,
migrate_to_latest,
)
from pystac.utils import is_absolute_href, make_absolute_href, make_relative_href
from pystac.utils import (
StringEnum,
is_absolute_href,
make_absolute_href,
make_relative_href,
)

if TYPE_CHECKING:
from pystac.asset import Asset as Asset_Type
from pystac.item import Item as Item_Type
from pystac.collection import Collection as Collection_Type


class CatalogType(str, Enum):
class CatalogType(StringEnum):
SELF_CONTAINED = "SELF_CONTAINED"
"""A 'self-contained catalog' is one that is designed for portability.
Users may want to download an online catalog from and be able to use it on their
Expand Down
11 changes: 5 additions & 6 deletions pystac/extensions/datacube.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"""

from abc import ABC
from enum import Enum
from typing import Any, Dict, Generic, List, Optional, TypeVar, Union, cast

import pystac
Expand All @@ -13,7 +12,7 @@
PropertiesExtension,
)
from pystac.extensions.hooks import ExtensionHooks
from pystac.utils import get_required
from pystac.utils import StringEnum, get_required

T = TypeVar("T", pystac.Collection, pystac.Item, pystac.Asset)

Expand Down Expand Up @@ -42,22 +41,22 @@
VAR_UNIT_PROP = "unit"


class DimensionType(str, Enum):
class DimensionType(StringEnum):
"""Dimension object types for spatial and temporal Dimension Objects."""

SPATIAL = "spatial"
TEMPORAL = "temporal"


class HorizontalSpatialDimensionAxis(str, Enum):
class HorizontalSpatialDimensionAxis(StringEnum):
"""Allowed values for ``axis`` field of :class:`HorizontalSpatialDimension`
object."""

X = "x"
Y = "y"


class VerticalSpatialDimensionAxis(str, Enum):
class VerticalSpatialDimensionAxis(StringEnum):
"""Allowed values for ``axis`` field of :class:`VerticalSpatialDimension`
object."""

Expand Down Expand Up @@ -407,7 +406,7 @@ def reference_system(self, v: Optional[Union[str, float, Dict[str, Any]]]) -> No
self.properties[DIM_REF_SYS_PROP] = v


class VariableType(str, Enum):
class VariableType(StringEnum):
"""Variable object types"""

DATA = "data"
Expand Down
5 changes: 2 additions & 3 deletions pystac/extensions/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
https://github.com/stac-extensions/file
"""

from enum import Enum
from typing import Any, Dict, List, Optional, Union

import pystac
Expand All @@ -14,7 +13,7 @@
STACJSONDescription,
STACVersionID,
)
from pystac.utils import get_required
from pystac.utils import StringEnum, get_required

SCHEMA_URI = "https://stac-extensions.github.io/file/v2.0.0/schema.json"

Expand All @@ -26,7 +25,7 @@
VALUES_PROP = PREFIX + "values"


class ByteOrder(str, Enum):
class ByteOrder(StringEnum):
"""List of allows values for the ``"file:byte_order"`` field defined by the
:stac-ext:`File Info Extension <file>`."""

Expand Down
11 changes: 5 additions & 6 deletions pystac/extensions/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
https://github.com/stac-extensions/label
"""

from enum import Enum
from pystac.extensions.base import ExtensionManagementMixin, SummariesExtension
from typing import Any, Dict, Iterable, List, Optional, Sequence, Union, cast

import pystac
from pystac.serialization.identify import STACJSONDescription, STACVersionID
from pystac.extensions.hooks import ExtensionHooks
from pystac.utils import get_required, map_opt
from pystac.utils import StringEnum, get_required, map_opt

SCHEMA_URI = "https://stac-extensions.github.io/label/v1.0.0/schema.json"

Expand All @@ -25,7 +24,7 @@
OVERVIEWS_PROP = PREFIX + "overviews"


class LabelRelType(str, Enum):
class LabelRelType(StringEnum):
"""A list of rel types defined in the Label Extension.

See the :stac-ext:`Label Extension Links <label#links-source-imagery>`
Expand All @@ -36,7 +35,7 @@ class LabelRelType(str, Enum):
"""Used to indicate a link to the source item to which a label item applies."""


class LabelType(str, Enum):
class LabelType(StringEnum):
"""Enumerates valid label types ("raster" or "vector")."""

VECTOR = "vector"
Expand All @@ -46,7 +45,7 @@ class LabelType(str, Enum):
"""Convenience attribute for checking if values are valid label types"""


class LabelTask(str, Enum):
class LabelTask(StringEnum):
"""Enumerates recommended values for "label:tasks" field."""

REGRESSION = "regression"
Expand All @@ -55,7 +54,7 @@ class LabelTask(str, Enum):
SEGMENTATION = "segmentation"


class LabelMethod(str, Enum):
class LabelMethod(StringEnum):
"""Enumerates recommended values for "label:methods" field."""

AUTOMATED = "automated"
Expand Down
7 changes: 3 additions & 4 deletions pystac/extensions/pointcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

https://github.com/stac-extensions/pointcloud
"""
from enum import Enum
from typing import Any, Dict, Generic, List, Optional, TypeVar, cast, Union

import pystac
Expand All @@ -13,7 +12,7 @@
)
from pystac.extensions.hooks import ExtensionHooks
from pystac.summaries import RangeSummary
from pystac.utils import map_opt, get_required
from pystac.utils import StringEnum, map_opt, get_required

T = TypeVar("T", pystac.Item, pystac.Asset)

Expand All @@ -28,7 +27,7 @@
STATISTICS_PROP = PREFIX + "statistics"


class PhenomenologyType(str, Enum):
class PhenomenologyType(StringEnum):
"""Valid values for the ``pc:type`` field in the :stac-ext:`Pointcloud Item
Properties <pointcloud#item-properties>`."""

Expand All @@ -39,7 +38,7 @@ class PhenomenologyType(str, Enum):
OTHER = "other"


class SchemaType(str, Enum):
class SchemaType(StringEnum):
"""Valid values for the ``type`` field in a :stac-ext:`Schema Object
<pointcloud#schema-object>`."""

Expand Down
7 changes: 3 additions & 4 deletions pystac/extensions/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
https://github.com/stac-extensions/raster
"""

import enum
from typing import Any, Dict, Iterable, List, Optional, Union

import pystac
Expand All @@ -12,19 +11,19 @@
PropertiesExtension,
SummariesExtension,
)
from pystac.utils import get_opt, get_required, map_opt
from pystac.utils import StringEnum, get_opt, get_required, map_opt

SCHEMA_URI = "https://stac-extensions.github.io/raster/v1.0.0/schema.json"

BANDS_PROP = "raster:bands"


class Sampling(str, enum.Enum):
class Sampling(StringEnum):
AREA = "area"
POINT = "point"


class DataType(str, enum.Enum):
class DataType(StringEnum):
INT8 = "int8"
INT16 = "int16"
INT32 = "int32"
Expand Down
9 changes: 4 additions & 5 deletions pystac/extensions/sar.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
https://github.com/stac-extensions/sar
"""

import enum
from typing import Any, Dict, Generic, Iterable, List, Optional, TypeVar, cast, Union

import pystac
Expand All @@ -15,7 +14,7 @@
SummariesExtension,
)
from pystac.extensions.hooks import ExtensionHooks
from pystac.utils import get_required, map_opt
from pystac.utils import StringEnum, get_required, map_opt

T = TypeVar("T", pystac.Item, pystac.Asset)

Expand All @@ -40,7 +39,7 @@
OBSERVATION_DIRECTION_PROP: str = PREFIX + "observation_direction"


class FrequencyBand(str, enum.Enum):
class FrequencyBand(StringEnum):
P = "P"
L = "L"
S = "S"
Expand All @@ -51,14 +50,14 @@ class FrequencyBand(str, enum.Enum):
KA = "Ka"


class Polarization(str, enum.Enum):
class Polarization(StringEnum):
HH = "HH"
VV = "VV"
HV = "HV"
VH = "VH"


class ObservationDirection(str, enum.Enum):
class ObservationDirection(StringEnum):
LEFT = "left"
RIGHT = "right"

Expand Down
5 changes: 2 additions & 3 deletions pystac/extensions/sat.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
https://github.com/stac-extensions/sat
"""

import enum
from datetime import datetime as Datetime
from pystac.summaries import RangeSummary
from typing import Dict, Any, List, Iterable, Generic, Optional, TypeVar, Union, cast
Expand All @@ -15,7 +14,7 @@
SummariesExtension,
)
from pystac.extensions.hooks import ExtensionHooks
from pystac.utils import str_to_datetime, datetime_to_str, map_opt
from pystac.utils import StringEnum, str_to_datetime, datetime_to_str, map_opt

T = TypeVar("T", pystac.Item, pystac.Asset)

Expand All @@ -31,7 +30,7 @@
ANX_DATETIME_PROP: str = PREFIX + "anx_datetime"


class OrbitState(str, enum.Enum):
class OrbitState(StringEnum):
ASCENDING = "ascending"
DESCENDING = "descending"
GEOSTATIONARY = "geostationary"
Expand Down
5 changes: 2 additions & 3 deletions pystac/extensions/scientific.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"""

import copy
from enum import Enum
from typing import Any, Dict, Generic, List, Optional, TypeVar, Union, cast
from urllib import parse

Expand All @@ -19,7 +18,7 @@
SummariesExtension,
)
from pystac.extensions.hooks import ExtensionHooks
from pystac.utils import map_opt
from pystac.utils import StringEnum, map_opt

T = TypeVar("T", pystac.Collection, pystac.Item)

Expand All @@ -35,7 +34,7 @@


# Link rel type.
class ScientificRelType(str, Enum):
class ScientificRelType(StringEnum):
"""A list of rel types defined in the Scientific Citation Extension.

See the :stac-ext:`Scientific Citation Extension Relation types
Expand Down
4 changes: 2 additions & 2 deletions pystac/extensions/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

https://github.com/stac-extensions/version
"""
from enum import Enum
from pystac.utils import get_required, map_opt
from typing import Generic, List, Optional, TypeVar, Union, cast

import pystac
from pystac.utils import StringEnum
from pystac.extensions.base import (
ExtensionManagementMixin,
PropertiesExtension,
Expand All @@ -23,7 +23,7 @@
DEPRECATED: str = "deprecated"


class VersionRelType(str, Enum):
class VersionRelType(StringEnum):
"""A list of rel types defined in the Version Extension.

See the `Version Extension Relation types
Expand Down
4 changes: 2 additions & 2 deletions pystac/media_type.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import Enum
from pystac.utils import StringEnum


class MediaType(str, Enum):
class MediaType(StringEnum):
"""A list of common media types that can be used in STAC Asset and Link metadata."""

COG = "image/tiff; application=geotiff; profile=cloud-optimized"
Expand Down
5 changes: 3 additions & 2 deletions pystac/provider.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from enum import Enum
from typing import Any, Dict, List, Optional

from pystac.utils import StringEnum

class ProviderRole(str, Enum):

class ProviderRole(StringEnum):
"""Enumerates the allows values of the Provider "role" field."""

LICENSOR = "licensor"
Expand Down
4 changes: 2 additions & 2 deletions pystac/rel_type.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import Enum
from pystac.utils import StringEnum


class RelType(str, Enum):
class RelType(StringEnum):
"""A list of common rel types that can be used in STAC Link metadata.
See :stac-spec:`"Using Relation Types <best-practices.md#using-relation-types>`
in the STAC Best Practices for guidelines on using relation types. You may also want
Expand Down
Loading