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

オープン 初心者向け
#1,702 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 6 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
mysql, numpy, postgresql, python
領域
databases

調査の方向性

まず src/datajoint/blob.py の CHAR のシリアライズと reshape のロジック、特に issue でリンクされている行を確認してください。提供された2行の 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時間
マージ済み PR(30日)
10

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

datajoint/datajoint-python のほかの issue

datajoint/datajoint-python の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。