Skip to content

Commit f5050ad

Browse files
Merge branch 'main' into reductionist_count_as_bytes
2 parents ff8477e + ab85d39 commit f5050ad

8 files changed

Lines changed: 238 additions & 74 deletions

File tree

.github/workflows/run-test-push.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ jobs:
3333
- run: conda list
3434
- run: flake8 --exclude tests,doc --max-line-length 120 --ignore F405,F401
3535
- run: pytest -n 2 -m "not slow" --junitxml=report-1.xml
36-
- uses: codecov/codecov-action@v5
36+
- uses: codecov/codecov-action@v6

activestorage/active.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ def hfix(x):
143143
missing_value = ds.attrs.get('missing_value')
144144
# see https://github.com/NCAS-CMS/PyActiveStorage/pull/303
145145
if isinstance(missing_value, np.ndarray):
146-
missing_value = missing_value[0]
146+
if missing_value.size == 1:
147+
missing_value = missing_value[0]
147148
valid_min = hfix(ds.attrs.get('valid_min'))
148149
valid_max = hfix(ds.attrs.get('valid_max'))
149150
valid_range = hfix(ds.attrs.get('valid_range'))
@@ -519,21 +520,22 @@ def _from_storage(self, ds, indexer, chunks, out_shape, out_dtype,
519520
# Create a shared session object.
520521
if self.interface_type == "s3" and self._version == 2:
521522
if self.storage_options is not None:
522-
key, secret = None, None
523523
if self.storage_options.get("anon", None) is True:
524524
print("Reductionist session for Anon S3 bucket.")
525525
session = reductionist.get_session(
526526
None, None, S3_ACTIVE_STORAGE_CACERT)
527-
if "key" in self.storage_options:
528-
key = self.storage_options["key"]
529-
if "secret" in self.storage_options:
530-
secret = self.storage_options["secret"]
531-
if key and secret:
532-
session = reductionist.get_session(
533-
key, secret, S3_ACTIVE_STORAGE_CACERT)
534527
else:
535-
session = reductionist.get_session(
536-
S3_ACCESS_KEY, S3_SECRET_KEY, S3_ACTIVE_STORAGE_CACERT)
528+
key, secret = None, None
529+
if "key" in self.storage_options:
530+
key = self.storage_options["key"]
531+
if "secret" in self.storage_options:
532+
secret = self.storage_options["secret"]
533+
if key and secret:
534+
session = reductionist.get_session(
535+
key, secret, S3_ACTIVE_STORAGE_CACERT)
536+
else:
537+
session = reductionist.get_session(
538+
S3_ACCESS_KEY, S3_SECRET_KEY, S3_ACTIVE_STORAGE_CACERT)
537539
else:
538540
session = reductionist.get_session(S3_ACCESS_KEY,
539541
S3_SECRET_KEY,

activestorage/reductionist.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,10 @@ def get_session(username: str, password: str,
2424
:returns: a client session object.
2525
"""
2626
session = requests.Session()
27-
# TODO Stack-HPC
28-
# we need to allow Anon buckets. though this
29-
# will break connection to data server
30-
# if username is None and password is None:
31-
# return session
32-
session.auth = (username, password)
3327
session.verify = cacert or False
28+
if username is None and password is None:
29+
return session
30+
session.auth = (username, password)
3431
return session
3532

3633

@@ -272,8 +269,13 @@ def __init__(self, status_code, error):
272269

273270
def decode_and_raise_error(response):
274271
"""Decode an error response and raise ReductionistError."""
275-
try:
276-
error = json.dumps(response.json())
272+
if response.status_code == http.client.INTERNAL_SERVER_ERROR:
273+
try:
274+
error = json.dumps(response.json())
275+
except requests.exceptions.JSONDecodeError as exc:
276+
error = http.client.responses.get(response.status_code, "-")
277+
raise ReductionistError(response.status_code, error) from exc
277278
raise ReductionistError(response.status_code, error)
278-
except requests.exceptions.JSONDecodeError as exc:
279-
raise ReductionistError(response.status_code, "-") from exc
279+
280+
error = http.client.responses.get(response.status_code, "-")
281+
raise ReductionistError(response.status_code, error)

activestorage/storage.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,19 @@ def mask_missing(data, missing):
130130
fill_value, missing_value, valid_min, valid_max = missing
131131

132132
if fill_value is not None:
133-
data = np.ma.masked_equal(data, fill_value)
133+
if isinstance(fill_value, np.ndarray) or isinstance(fill_value, list):
134+
data = np.ma.masked_where(data == fill_value, data)
135+
else:
136+
data = np.ma.masked_equal(data, fill_value)
134137

135138
if missing_value is not None:
136-
data = np.ma.masked_equal(data, missing_value)
139+
if isinstance(missing_value, np.ndarray) or isinstance(missing_value, list):
140+
try:
141+
data = np.ma.masked_where(data == missing_value, data)
142+
except ValueError: # not broadcastable
143+
raise ValueError("Data and missing_value arrays are not brodcastable!")
144+
else:
145+
data = np.ma.masked_equal(data, missing_value)
137146

138147
if valid_max is not None:
139148
data = np.ma.masked_greater(data, valid_max)

0 commit comments

Comments
 (0)