Character matrices with more than one row come back transposed from <blob>

未关闭 适合新手
#1,702 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 6 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
mysql, numpy, postgresql, python
领域
databases

调研方向

从 src/datajoint/blob.py 中 CHAR 序列化和重塑逻辑入手,尤其是 issue 中链接的代码行。使用提供的两行 NumPy 数组复现往返过程,然后检查按列写入是否能保留由 Python 存储的 blob,同时为 MATLAB 生成预期的矩阵。字符矩阵往返后保持不变,且 MATLAB 读取后也保持不变,即表示完成。

由索引模型根据 Issue 内容生成。

描述

bug

A character array (S1) with two or more rows comes back transposed from a <blob> attribute.

import numpy as np
from datajoint import blob

x = np.array([[b"a", b"b", b"c"], [b"d", b"e", b"f"]])
blob.unpack(blob.pack(x))
# array([['a', 'c', 'e'],
#        ['b', 'd', 'f']], dtype='<U1')

The same happens through a table (insert1 and fetch1 on a <blob> attribute), on MySQL and PostgreSQL, with master at eefe74b4.

The writer stores CHAR data in row-major order: array.view(np.uint8).astype(np.uint16).tobytes() (blob.py#L345). The reader reshapes it in column-major order (blob.py#L309), which is how MATLAB writes it and how every other array type is written. Bytes laid out the MATLAB way read back correctly. Commit 8f868518 (2019) changed the writer from array.tobytes(order='F') to the current form.

One-row and one-dimensional character arrays are not affected, because they are read back as a single string.

Expected

A character matrix round-trips unchanged, and MATLAB reads it unchanged.

Suggested fix

Write the CHAR data in column-major order: array.view(np.uint8).astype(np.uint16).tobytes(order="F"). Values already stored by Python keep their row-major bytes, so they read back as they do today.

主要语言
Python
星标
198
派生
103
平均合并
6 天 1 小时
30 天内合并 PR
10

环境准备

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

datajoint/datajoint-python 的其他 Issue

查看 datajoint/datajoint-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。