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

[Bug]: Support writing multidimensional string datasets and attributes #1096

Closed
rly opened this issue Apr 12, 2024 · 1 comment · Fixed by #1173
Closed

[Bug]: Support writing multidimensional string datasets and attributes #1096

rly opened this issue Apr 12, 2024 · 1 comment · Fixed by #1173
Assignees
Labels
category: bug errors in the code or code behavior priority: medium non-critical problem and/or affecting only a small set of users
Milestone

Comments

@rly
Copy link
Contributor

rly commented Apr 12, 2024

What happened?

In trying to resolve NeurodataWithoutBorders/pynwb#1886 in HDMF, I discovered that on build, a multidimensional list or array that maps to a multidimensional dataset/attribute spec is converted to a 1-D list or array.

[['a', 'b'], ['c', 'd']] -> ["['a', 'b']", "['c', 'd']"]
np.array([['a', 'b'], ['c', 'd']]) -> array(["['a' 'b']", "['c' 'd']"], dtype='<U9')

Steps to Reproduce

def test_build_2d_lol(self):
        bar_spec = GroupSpec(
            doc='A test group specification with a data type',
            data_type_def='Bar',
            datasets=[
                DatasetSpec(
                    doc='an example dataset',
                    dtype='text',
                    name='data',
                    shape=(None, None),
                    attributes=[AttributeSpec(name='attr2', doc='an example integer attribute', dtype='int')],
                )
            ],
            attributes=[AttributeSpec(name='attr1', doc='an example string attribute', dtype='text')],
        )
        type_map = self.customSetUp(bar_spec)
        type_map.register_map(Bar, BarMapper)
        bar_inst = Bar('my_bar', [['a', 'b'], ['c', 'd']], 'value1', 10)
        builder = type_map.build(bar_inst)
        self.assertEqual(builder.get('data').data, [['a', 'b'], ['c', 'd']])

    def test_build_2d_ndarray(self):
        bar_spec = GroupSpec(
            doc='A test group specification with a data type',
            data_type_def='Bar',
            datasets=[
                DatasetSpec(
                    doc='an example dataset',
                    dtype='text',
                    name='data',
                    shape=(None, None),
                    attributes=[AttributeSpec(name='attr2', doc='an example integer attribute', dtype='int')],
                )
            ],
            attributes=[AttributeSpec(name='attr1', doc='an example string attribute', dtype='text')],
        )
        type_map = self.customSetUp(bar_spec)
        type_map.register_map(Bar, BarMapper)
        bar_inst = Bar('my_bar', np.array([['a', 'b'], ['c', 'd']]), 'value1', 10)
        builder = type_map.build(bar_inst)
        np.testing.assert_array_equal(builder.get('data').data, np.array([['a', 'b'], ['c', 'd']]))

Traceback

No response

Operating System

macOS

Python Executable

Conda

Python Version

3.12

Package Versions

No response

@rly rly self-assigned this Apr 12, 2024
@rly rly added category: bug errors in the code or code behavior priority: medium non-critical problem and/or affecting only a small set of users labels Apr 12, 2024
@rly
Copy link
Contributor Author

rly commented Apr 12, 2024

I'm working on a fix already.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: bug errors in the code or code behavior priority: medium non-critical problem and/or affecting only a small set of users
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants