Skip to content

Commit 66d32f3

Browse files
dfa1claude
andcommitted
review: clarify isUnsigned javadoc; pin signed-I8 rendering
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 66478a0 commit 66d32f3

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

csv/src/main/java/io/github/dfa1/vortex/csv/CsvExporter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ private static String cellValue(Array arr, long rowIdx) {
166166

167167
/// Whether the array's dtype is an unsigned integer, so high-half values must render as
168168
/// unsigned decimal rather than the two's-complement negative that the raw signed getter
169-
/// returns. A [MaskedArray]'s inner array carries the same ptype, so recursing is safe.
169+
/// returns. Callers only pass leaf value arrays: the [MaskedArray] arm of `cellValue`
170+
/// recurses into the inner array before any integer arm is reached.
170171
private static boolean isUnsigned(Array arr) {
171172
return arr.dtype() instanceof DType.Primitive p && p.ptype().isUnsigned();
172173
}

csv/src/test/java/io/github/dfa1/vortex/csv/CsvExporterTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,29 @@ void rendersNullableU8HighHalfAsUnsigned(@TempDir Path tmp) throws Exception {
143143
assertThat(result).containsExactly("magnesium", "132", "", "162");
144144
}
145145

146+
@Test
147+
void keepsSignedI8Negative(@TempDir Path tmp) throws Exception {
148+
// Given a SIGNED I8 column with a negative value — pins that the unsigned-rendering
149+
// fix did not widen signed bytes: -5 must stay "-5", not become "251"
150+
Path vortex = tmp.resolve("i8.vortex");
151+
DType.Struct schema = new DType.Struct(
152+
List.of(ColumnName.of("delta")),
153+
List.of(new DType.Primitive(PType.I8, false)),
154+
false);
155+
try (FileChannel ch = FileChannel.open(vortex, StandardOpenOption.CREATE, StandardOpenOption.WRITE);
156+
VortexWriter writer = VortexWriter.create(ch, schema, WriteOptions.defaults())) {
157+
writer.writeChunk(Map.of(ColumnName.of("delta"), new byte[]{(byte) -5, (byte) 7}));
158+
}
159+
Path csv = tmp.resolve("out.csv");
160+
161+
// When
162+
CsvExporter.exportCsv(vortex, csv);
163+
164+
// Then
165+
List<String> result = Files.readAllLines(csv);
166+
assertThat(result).containsExactly("delta", "-5", "7");
167+
}
168+
146169
@Test
147170
void rendersU16HighHalfAsUnsigned(@TempDir Path tmp) throws Exception {
148171
// Given a non-nullable U16 column. 40000 is 0x9C40, which is -25536 as a signed short.

0 commit comments

Comments
 (0)