Skip to content

Commit

Permalink
Merge pull request #539 from AllenInstitute/release-1.0.5
Browse files Browse the repository at this point in the history
Release 1.0.5
  • Loading branch information
MatthewAitken authored Dec 13, 2021
2 parents db47e37 + 7fee477 commit 905ee74
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 25 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ All notable changes to this project will be documented in this file.
### Added

### Changed
- adjusted get_stimulus_epoch to require a complete stimulus (both onset and offset) to define the stimulus epoch

## [1.0.5] = 2021-12-13
Bug fixes:
- Converts nwb_version attribute to string if it is in utf-8 encoded bytes.

## [1.0.4] = 2021-07-29
Changed:
Expand Down
14 changes: 7 additions & 7 deletions ipfx/dataset/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from ipfx.stimulus import StimulusOntology
from ipfx.dataset.hbg_nwb_data import HBGNWBData
from ipfx.dataset.mies_nwb_data import MIESNWBData
from ipfx import py2to3
from ipfx.string_utils import to_str
from ipfx.dataset.labnotebook import LabNotebookReaderIgorNwb


Expand Down Expand Up @@ -59,20 +59,20 @@ def get_nwb_version(nwb_file: str) -> Dict[str, Any]:
with h5py.File(nwb_file, 'r') as f:
if "nwb_version" in f: # In version 0 and 1 this is a dataset
nwb_version = get_scalar_value(f["nwb_version"][()])
nwb_version_str = py2to3.to_str(nwb_version)
nwb_version_str = to_str(nwb_version)
if nwb_version is not None and re.match("^NWB-", nwb_version_str):
return {
"major": int(nwb_version_str[4]),
"full": nwb_version_str
}

elif "nwb_version" in f.attrs: # in version 2 this is an attribute
nwb_version = f.attrs["nwb_version"]
if nwb_version is not None and (
re.match("^2", nwb_version) or
re.match("^NWB-2", nwb_version)
nwb_version_str = to_str(f.attrs["nwb_version"])
if nwb_version_str is not None and (
re.match("^2", nwb_version_str) or
re.match("^NWB-2", nwb_version_str)
):
return {"major": 2, "full": nwb_version}
return {"major": 2, "full": nwb_version_str}

return {"major": None, "full": None}

Expand Down
2 changes: 1 addition & 1 deletion ipfx/dataset/labnotebook.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import h5py
import math
from ipfx.py2to3 import to_str
from ipfx.string_utils import to_str

class LabNotebookReader(object):
"""
Expand Down
2 changes: 1 addition & 1 deletion ipfx/lims_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from allensdk.core.authentication import credential_injector
from allensdk.core.auth_config import LIMS_DB_CREDENTIAL_MAP

from ipfx.py2to3 import to_str
from ipfx.string_utils import to_str


TIMEOUT = os.environ.get(
Expand Down
13 changes: 0 additions & 13 deletions ipfx/py2to3.py

This file was deleted.

20 changes: 20 additions & 0 deletions ipfx/string_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from typing import Union

def to_str(s: Union[str, bytes]
)-> str:
"""Convert bytes to string if not string
Parameters
----------
s (Union[str,bytes]): variable to convert
Returns
-------
str
"""
if isinstance(s, bytes):
return s.decode('utf-8')
else:
return s

2 changes: 1 addition & 1 deletion ipfx/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.4
1.0.5
3 changes: 2 additions & 1 deletion requirements_docs.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
sphinx
sphinx-gallery
m2r
numpydoc>=0.6.0,<1.0.0
numpydoc>=0.6.0,<1.0.0
mistune<2
22 changes: 22 additions & 0 deletions tests/test_string_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from ipfx.string_utils import to_str
import pytest




@pytest.mark.parametrize(
"input, expected",
[
# Case 0: supplied string
(
"a_string", "a_string"
),
# Case 1: supplied bytes
(
b"a_string", "a_string"
),
]
)
def test_to_string(input, expected):
obtained = to_str(input)
assert obtained == expected

0 comments on commit 905ee74

Please sign in to comment.