Skip to content

Commit

Permalink
update nzhsm-common dependency to ^0.6.0 (#39)
Browse files Browse the repository at this point in the history
* update nzhsm-common dependency to ^0.6.0
* remove version control from ToshiOpenquakeMeta
* mock cache when testing hazard aggregation query
* update changelog
* Bump version: 0.7.0 → 0.7.1
  • Loading branch information
chrisdicaprio authored Apr 24, 2023
1 parent 6495c9e commit ea382e3
Show file tree
Hide file tree
Showing 10 changed files with 1,476 additions and 1,492 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.7.0
current_version = 0.7.1
commit = True
tag = True

Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [0.7.1] - 2023-4-24
### Changed
- update nzshm-common dependency 0.6.0
- mock cache when testing hazard aggregation query

### Removed
- remove version control for ToshiOpenquakeMeta
## [0.7.0] - 2023-04-17
### Changed
- update openquake dependency 3.16
Expand Down
2,917 changes: 1,449 additions & 1,468 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool]
[tool.poetry]
name = "toshi-hazard-store"
version = "0.7.0"
version = "0.7.1"
homepage = "https://github.com/GNS-Science/toshi-hazard-store"
description = "Library for saving and retrieving NZHSM openquake hazard results with convenience (uses AWS Dynamodb)."
authors = ["GNS Science <[email protected]>"]
Expand Down Expand Up @@ -32,12 +32,12 @@ ths_cache = 'scripts.ths_cache:cli'

[tool.poetry.dependencies]
numpy = "^1.23.1"
nzshm-common = "^0.5.0"
openquake-engine = {version = "^3.16", optional = true}
pandas = "^1.4.3"
pynamodb = "^5.2.1"
pynamodb-attributes = "^0.3.2"
python = ">=3.8,<4.0"
nzshm-common = "^0.6.0"

[tool.poetry.group.dev.dependencies]
black = { version = "^22.3"}
Expand Down
3 changes: 3 additions & 0 deletions tests/test_hazard_aggregation_to_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import io
import unittest

from unittest.mock import patch

from moto import mock_dynamodb

from toshi_hazard_store import model, query_v3
Expand All @@ -24,6 +26,7 @@ def tearDown(self):
model.drop_tables()
return super(QueryHazardAggregationV3Csv, self).tearDown()

@patch("toshi_hazard_store.model.caching.cache_store.LOCAL_CACHE_FOLDER", None)
def test_query_and_serialise_csv(self):
qlocs = [loc.downsample(0.001).code for loc in locs[:2]]
res = list(query_v3.get_hazard_curves(qlocs, vs30s, [HAZARD_MODEL_ID], imts))
Expand Down
12 changes: 1 addition & 11 deletions tests/test_pynamo_models_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,8 @@ def test_table_exists(self):
def test_save_one_meta_object(self):
obj = get_one_meta()

print(f'obj: {obj} {obj.version}')
self.assertEqual(obj.version, None)
obj.save()
self.assertEqual(obj.version, 1)

def test_save_duplicate_raises(self):
meta_a = get_one_meta()
meta_a.save()

meta_b = get_one_meta()
with self.assertRaises(pynamodb.exceptions.PutError):
meta_b.save()
self.assertEqual(obj.inv_time, 1.0)


@mock_dynamodb
Expand Down
3 changes: 3 additions & 0 deletions tests/test_query_hazard_agg_v3.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import itertools
import unittest

from unittest.mock import patch

from moto import mock_dynamodb
from nzshm_common.location.code_location import CodedLocation
from nzshm_common.location.location import LOCATIONS_BY_ID
Expand Down Expand Up @@ -29,6 +31,7 @@ def build_hazard_aggregation_models():
).set_location(loc)


@patch("toshi_hazard_store.model.caching.cache_store.LOCAL_CACHE_FOLDER", None)
@mock_dynamodb
class QueryHazardAggregationV3Test(unittest.TestCase):
def setUp(self):
Expand Down
8 changes: 8 additions & 0 deletions tests/test_query_hazard_agg_vs30_fix.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import itertools
import unittest
from unittest.mock import patch

from moto import mock_dynamodb
from nzshm_common.location.code_location import CodedLocation
Expand Down Expand Up @@ -29,6 +30,7 @@ def build_hazard_aggregation_models():
).set_location(loc)


@patch("toshi_hazard_store.model.caching.cache_store.LOCAL_CACHE_FOLDER", None)
@mock_dynamodb
class QueryHazardAggregationV3TestVS30(unittest.TestCase):
def setUp(self):
Expand All @@ -42,6 +44,7 @@ def tearDown(self):
model.drop_tables()
return super(QueryHazardAggregationV3TestVS30, self).tearDown()

# @patch("toshi_hazard_store.model.caching.cache_store.LOCAL_CACHE_FOLDER", None)
def test_query_hazard_aggr_with_vs30_mixed_A(self):
vs30s = [250, 1500]
qlocs = [loc.downsample(0.001).code for loc in locs]
Expand All @@ -50,6 +53,7 @@ def test_query_hazard_aggr_with_vs30_mixed_A(self):
print(res)
self.assertEqual(len(res), len(imts) * len(aggs) * len(vs30s) * len(locs))

# @patch("toshi_hazard_store.model.caching.cache_store.LOCAL_CACHE_FOLDER", None)
def test_query_hazard_aggr_with_vs30_mixed_B(self):
vs30s = [500, 1000]
qlocs = [loc.downsample(0.001).code for loc in locs]
Expand All @@ -58,24 +62,28 @@ def test_query_hazard_aggr_with_vs30_mixed_B(self):
print(res)
self.assertEqual(len(res), len(imts) * len(aggs) * len(vs30s) * len(locs))

# @patch("toshi_hazard_store.model.caching.cache_store.LOCAL_CACHE_FOLDER", None)
def test_query_hazard_aggr_with_vs30_one_long(self):
vs30s = [1500]
qlocs = [loc.downsample(0.001).code for loc in locs]
res = list(query_v3.get_hazard_curves(qlocs, vs30s, [HAZARD_MODEL_ID], imts))
self.assertEqual(len(res), len(imts) * len(aggs) * len(vs30s) * len(locs))

# @patch("toshi_hazard_store.model.caching.cache_store.LOCAL_CACHE_FOLDER", None)
def test_query_hazard_aggr_with_vs30_two_long(self):
vs30s = [1000, 1500]
qlocs = [loc.downsample(0.001).code for loc in locs]
res = list(query_v3.get_hazard_curves(qlocs, vs30s, [HAZARD_MODEL_ID], imts))
self.assertEqual(len(res), len(imts) * len(aggs) * len(vs30s) * len(locs))

# @patch("toshi_hazard_store.model.caching.cache_store.LOCAL_CACHE_FOLDER", None)
def test_query_hazard_aggr_with_vs30_one_short(self):
vs30s = [500]
qlocs = [loc.downsample(0.001).code for loc in locs]
res = list(query_v3.get_hazard_curves(qlocs, vs30s, [HAZARD_MODEL_ID], imts))
self.assertEqual(len(res), len(imts) * len(aggs) * len(vs30s) * len(locs))

# @patch("toshi_hazard_store.model.caching.cache_store.LOCAL_CACHE_FOLDER", None)
def test_query_hazard_aggr_with_vs30_two_short(self):
vs30s = [250, 500]
qlocs = [loc.downsample(0.001).code for loc in locs]
Expand Down
2 changes: 1 addition & 1 deletion toshi_hazard_store/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

__author__ = """GNS Science"""
__email__ = '[email protected]'
__version__ = '0.7.0'
__version__ = '0.7.1'


import toshi_hazard_store.model as model
Expand Down
10 changes: 1 addition & 9 deletions toshi_hazard_store/model/openquake_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,7 @@
from typing import Iterable, Iterator, Sequence, Union

from nzshm_common.location.code_location import CodedLocation
from pynamodb.attributes import (
JSONAttribute,
ListAttribute,
NumberAttribute,
UnicodeAttribute,
UnicodeSetAttribute,
VersionAttribute,
)
from pynamodb.attributes import JSONAttribute, ListAttribute, NumberAttribute, UnicodeAttribute, UnicodeSetAttribute
from pynamodb.indexes import AllProjection, LocalSecondaryIndex
from pynamodb.models import Model
from pynamodb_attributes import IntegerAttribute, TimestampAttribute
Expand Down Expand Up @@ -41,7 +34,6 @@ class Meta:
partition_key = UnicodeAttribute(hash_key=True) # a static value as we actually don't want to partition our data
hazsol_vs30_rk = UnicodeAttribute(range_key=True)

version = VersionAttribute()
created = TimestampAttribute(default=datetime_now)

hazard_solution_id = UnicodeAttribute()
Expand Down

0 comments on commit ea382e3

Please sign in to comment.