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

Added test for to_hierarchical_dataframe for the icephys tables #1404

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
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 @@ -4,6 +4,7 @@

### Bug fixes:
- Add `environment-ros3.yml` to `MANIFEST.in` for inclusion in source distributions. @rly (#1398)
- Update HDMF minimum version to `3.1.2` to fix bug when converting the icephys metadata tables via `to_hierarchical_dataframe` when the tables contain indexed columns and add corresponding unit tests. @oruebel (#1404)

## PyNWB 2.0.0 (August 13, 2021)

Expand Down
2 changes: 1 addition & 1 deletion requirements-min.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# minimum versions of package dependencies for installing PyNWB
h5py==2.10 # support for selection of datasets with list of indices added in 2.10
hdmf==3.1.1
hdmf==3.1.2
numpy==1.16
pandas==1.0.5
python-dateutil==2.7
Expand Down
57 changes: 57 additions & 0 deletions tests/unit/test_icephys_metadata_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
from pynwb.base import TimeSeriesReferenceVectorData
from pynwb import NWBHDF5IO
from hdmf.utils import docval, popargs
from pynwb.testing import create_icephys_testfile
from hdmf.common.hierarchicaltable import to_hierarchical_dataframe


class ICEphysMetaTestBase(TestCase):
Expand Down Expand Up @@ -889,6 +891,61 @@ def test_enforce_unique_id(self):
with self.assertRaises(ValueError):
cond.add_experimental_condition(repetitions=[0, ], id=np.int64(10))

def test_to_hierarchical_dataframe(self):
# test that to_hierarchical_dataframe works for the icephys tables when only containing regular VectorData
nwbfile = create_icephys_testfile()
temp = to_hierarchical_dataframe(nwbfile.icephys_experimental_conditions)
expected_index = [
(100000, 32.0, 10000, 'R1', 1000, 'StimType_1', 'T1', 100, 0),
(100000, 32.0, 10000, 'R1', 1000, 'StimType_1', 'T1', 100, 0),
(100000, 32.0, 10000, 'R1', 1000, 'StimType_1', 'T1', 101, 1),
(100000, 32.0, 10000, 'R1', 1000, 'StimType_1', 'T1', 101, 1),
(100000, 32.0, 10001, 'R2', 1001, 'StimType_2', 'T2', 102, 2),
(100000, 32.0, 10001, 'R2', 1001, 'StimType_2', 'T2', 102, 2),
(100000, 32.0, 10001, 'R2', 1001, 'StimType_2', 'T2', 102, 2),
(100000, 32.0, 10001, 'R2', 1002, 'StimType_3', 'T3', 103, 3),
(100000, 32.0, 10001, 'R2', 1002, 'StimType_3', 'T3', 103, 3),
(100000, 32.0, 10001, 'R2', 1002, 'StimType_3', 'T3', 103, 3),
(100001, 24.0, 10002, 'R1', 1003, 'StimType_1', 'T1', 104, 4),
(100001, 24.0, 10002, 'R1', 1003, 'StimType_1', 'T1', 104, 4),
(100001, 24.0, 10002, 'R1', 1003, 'StimType_1', 'T1', 105, 5),
(100001, 24.0, 10002, 'R1', 1003, 'StimType_1', 'T1', 105, 5),
(100001, 24.0, 10003, 'R2', 1004, 'StimType_2', 'T2', 106, 6),
(100001, 24.0, 10003, 'R2', 1004, 'StimType_2', 'T2', 106, 6),
(100001, 24.0, 10003, 'R2', 1004, 'StimType_2', 'T2', 106, 6),
(100001, 24.0, 10003, 'R2', 1005, 'StimType_3', 'T3', 107, 7),
(100001, 24.0, 10003, 'R2', 1005, 'StimType_3', 'T3', 107, 7),
(100001, 24.0, 10003, 'R2', 1005, 'StimType_3', 'T3', 107, 7)]
self.assertListEqual(temp.index.tolist(), expected_index)

def test_to_hierarchical_dataframe_with_indexed_custom_column(self):
# test that to_hierarchical_dataframe works for the icephys tables when containing also VectorIndex columns
nwbfile = create_icephys_testfile()
nwbfile.icephys_experimental_conditions.add_column('newcol', 'abc', data=[1, 2, 3], index=[2, 3])
temp = to_hierarchical_dataframe(nwbfile.icephys_experimental_conditions)
expected_index = [
(100000, 32.0, (1, 2), 10000, 'R1', 1000, 'StimType_1', 'T1', 100, 0),
(100000, 32.0, (1, 2), 10000, 'R1', 1000, 'StimType_1', 'T1', 100, 0),
(100000, 32.0, (1, 2), 10000, 'R1', 1000, 'StimType_1', 'T1', 101, 1),
(100000, 32.0, (1, 2), 10000, 'R1', 1000, 'StimType_1', 'T1', 101, 1),
(100000, 32.0, (1, 2), 10001, 'R2', 1001, 'StimType_2', 'T2', 102, 2),
(100000, 32.0, (1, 2), 10001, 'R2', 1001, 'StimType_2', 'T2', 102, 2),
(100000, 32.0, (1, 2), 10001, 'R2', 1001, 'StimType_2', 'T2', 102, 2),
(100000, 32.0, (1, 2), 10001, 'R2', 1002, 'StimType_3', 'T3', 103, 3),
(100000, 32.0, (1, 2), 10001, 'R2', 1002, 'StimType_3', 'T3', 103, 3),
(100000, 32.0, (1, 2), 10001, 'R2', 1002, 'StimType_3', 'T3', 103, 3),
(100001, 24.0, (3,), 10002, 'R1', 1003, 'StimType_1', 'T1', 104, 4),
(100001, 24.0, (3,), 10002, 'R1', 1003, 'StimType_1', 'T1', 104, 4),
(100001, 24.0, (3,), 10002, 'R1', 1003, 'StimType_1', 'T1', 105, 5),
(100001, 24.0, (3,), 10002, 'R1', 1003, 'StimType_1', 'T1', 105, 5),
(100001, 24.0, (3,), 10003, 'R2', 1004, 'StimType_2', 'T2', 106, 6),
(100001, 24.0, (3,), 10003, 'R2', 1004, 'StimType_2', 'T2', 106, 6),
(100001, 24.0, (3,), 10003, 'R2', 1004, 'StimType_2', 'T2', 106, 6),
(100001, 24.0, (3,), 10003, 'R2', 1005, 'StimType_3', 'T3', 107, 7),
(100001, 24.0, (3,), 10003, 'R2', 1005, 'StimType_3', 'T3', 107, 7),
(100001, 24.0, (3,), 10003, 'R2', 1005, 'StimType_3', 'T3', 107, 7)]
self.assertListEqual(temp.index.tolist(), expected_index)


class NWBFileTests(TestCase):
"""
Expand Down