Skip to content

Commit 25a159b

Browse files
committed
Rename NullabilityOptions.Keeping to Infer, use NullabilityOptions.Widening in ArrowFeather.readDataFrame
1 parent f31c8bd commit 25a159b

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/TypeConversions.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public enum class NullabilityOptions {
199199
* Use only actual data, set [DataColumn.hasNulls] to true if and only if there are null values in the column.
200200
* On empty dataset use False.
201201
*/
202-
Keeping,
202+
Infer,
203203

204204
/**
205205
* Set [DataColumn.hasNulls] to expected value. Throw exception if column should be not nullable but there are null values.
@@ -221,7 +221,7 @@ public class NullabilityException() : Exception()
221221
public fun NullabilityOptions.applyNullability(data: List<Any?>, expectedNulls: Boolean): Boolean {
222222
val hasNulls = data.anyNull()
223223
return when (this) {
224-
NullabilityOptions.Keeping -> hasNulls
224+
NullabilityOptions.Infer -> hasNulls
225225
NullabilityOptions.Checking -> {
226226
if (!expectedNulls && hasNulls) {
227227
throw NullabilityException()

dataframe-arrow/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/arrow.kt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ import kotlin.reflect.full.withNullability
6666
import kotlin.reflect.typeOf
6767

6868
public class ArrowFeather : SupportedFormat {
69-
override fun readDataFrame(stream: InputStream, header: List<String>): AnyFrame = DataFrame.readArrowFeather(stream)
69+
override fun readDataFrame(stream: InputStream, header: List<String>): AnyFrame = DataFrame.readArrowFeather(stream, NullabilityOptions.Widening)
7070

71-
override fun readDataFrame(file: File, header: List<String>): AnyFrame = DataFrame.readArrowFeather(file)
71+
override fun readDataFrame(file: File, header: List<String>): AnyFrame = DataFrame.readArrowFeather(file, NullabilityOptions.Widening)
7272

7373
override fun acceptsExtension(ext: String): Boolean = ext == "feather"
7474

@@ -111,7 +111,7 @@ internal fun <T> Iterable<DataFrame<T>>.concatKeepingSchema(): DataFrame<T> {
111111
/**
112112
* Read [Arrow interprocess streaming format](https://arrow.apache.org/docs/java/ipc.html#writing-and-reading-streaming-format) data from existing [channel]
113113
*/
114-
public fun DataFrame.Companion.readArrowIPC(channel: ReadableByteChannel, allocator: RootAllocator = Allocator.ROOT, nullability: NullabilityOptions = NullabilityOptions.Keeping): AnyFrame {
114+
public fun DataFrame.Companion.readArrowIPC(channel: ReadableByteChannel, allocator: RootAllocator = Allocator.ROOT, nullability: NullabilityOptions = NullabilityOptions.Infer): AnyFrame {
115115
ArrowStreamReader(channel, allocator).use { reader ->
116116
val dfs = buildList {
117117
val root = reader.vectorSchemaRoot
@@ -128,7 +128,7 @@ public fun DataFrame.Companion.readArrowIPC(channel: ReadableByteChannel, alloca
128128
/**
129129
* Read [Arrow random access format](https://arrow.apache.org/docs/java/ipc.html#writing-and-reading-random-access-files) data from existing [channel]
130130
*/
131-
public fun DataFrame.Companion.readArrowFeather(channel: SeekableByteChannel, allocator: RootAllocator = Allocator.ROOT, nullability: NullabilityOptions = NullabilityOptions.Keeping): AnyFrame {
131+
public fun DataFrame.Companion.readArrowFeather(channel: SeekableByteChannel, allocator: RootAllocator = Allocator.ROOT, nullability: NullabilityOptions = NullabilityOptions.Infer): AnyFrame {
132132
ArrowFileReader(channel, allocator).use { reader ->
133133
val dfs = buildList {
134134
reader.recordBlocks.forEach { block ->
@@ -274,25 +274,25 @@ private fun readField(root: VectorSchemaRoot, field: Field, nullability: Nullabi
274274
/**
275275
* Read [Arrow interprocess streaming format](https://arrow.apache.org/docs/java/ipc.html#writing-and-reading-streaming-format) data from existing [file]
276276
*/
277-
public fun DataFrame.Companion.readArrowIPC(file: File, nullability: NullabilityOptions = NullabilityOptions.Keeping): AnyFrame =
277+
public fun DataFrame.Companion.readArrowIPC(file: File, nullability: NullabilityOptions = NullabilityOptions.Infer): AnyFrame =
278278
Files.newByteChannel(file.toPath()).use { readArrowIPC(it, nullability = nullability) }
279279

280280
/**
281281
* Read [Arrow interprocess streaming format](https://arrow.apache.org/docs/java/ipc.html#writing-and-reading-streaming-format) data from existing [byteArray]
282282
*/
283-
public fun DataFrame.Companion.readArrowIPC(byteArray: ByteArray, nullability: NullabilityOptions = NullabilityOptions.Keeping): AnyFrame =
283+
public fun DataFrame.Companion.readArrowIPC(byteArray: ByteArray, nullability: NullabilityOptions = NullabilityOptions.Infer): AnyFrame =
284284
SeekableInMemoryByteChannel(byteArray).use { readArrowIPC(it, nullability = nullability) }
285285

286286
/**
287287
* Read [Arrow interprocess streaming format](https://arrow.apache.org/docs/java/ipc.html#writing-and-reading-streaming-format) data from existing [stream]
288288
*/
289-
public fun DataFrame.Companion.readArrowIPC(stream: InputStream, nullability: NullabilityOptions = NullabilityOptions.Keeping): AnyFrame =
289+
public fun DataFrame.Companion.readArrowIPC(stream: InputStream, nullability: NullabilityOptions = NullabilityOptions.Infer): AnyFrame =
290290
Channels.newChannel(stream).use { readArrowIPC(it, nullability = nullability) }
291291

292292
/**
293293
* Read [Arrow interprocess streaming format](https://arrow.apache.org/docs/java/ipc.html#writing-and-reading-streaming-format) data from existing [url]
294294
*/
295-
public fun DataFrame.Companion.readArrowIPC(url: URL, nullability: NullabilityOptions = NullabilityOptions.Keeping): AnyFrame =
295+
public fun DataFrame.Companion.readArrowIPC(url: URL, nullability: NullabilityOptions = NullabilityOptions.Infer): AnyFrame =
296296
when {
297297
isFile(url) -> readArrowIPC(urlAsFile(url), nullability)
298298
isProtocolSupported(url) -> url.openStream().use { readArrowIPC(it, nullability) }
@@ -301,7 +301,7 @@ public fun DataFrame.Companion.readArrowIPC(url: URL, nullability: NullabilityOp
301301
}
302302
}
303303

304-
public fun DataFrame.Companion.readArrowIPC(path: String, nullability: NullabilityOptions = NullabilityOptions.Keeping): AnyFrame = if (isURL(path)) {
304+
public fun DataFrame.Companion.readArrowIPC(path: String, nullability: NullabilityOptions = NullabilityOptions.Infer): AnyFrame = if (isURL(path)) {
305305
readArrowIPC(URL(path), nullability)
306306
} else {
307307
readArrowIPC(File(path), nullability)
@@ -312,25 +312,25 @@ public fun DataFrame.Companion.readArrowIPC(path: String, nullability: Nullabili
312312
/**
313313
* Read [Arrow random access format](https://arrow.apache.org/docs/java/ipc.html#writing-and-reading-random-access-files) data from existing [file]
314314
*/
315-
public fun DataFrame.Companion.readArrowFeather(file: File, nullability: NullabilityOptions = NullabilityOptions.Keeping): AnyFrame =
315+
public fun DataFrame.Companion.readArrowFeather(file: File, nullability: NullabilityOptions = NullabilityOptions.Infer): AnyFrame =
316316
Files.newByteChannel(file.toPath()).use { readArrowFeather(it, nullability = nullability) }
317317

318318
/**
319319
* Read [Arrow random access format](https://arrow.apache.org/docs/java/ipc.html#writing-and-reading-random-access-files) data from existing [byteArray]
320320
*/
321-
public fun DataFrame.Companion.readArrowFeather(byteArray: ByteArray, nullability: NullabilityOptions = NullabilityOptions.Keeping): AnyFrame =
321+
public fun DataFrame.Companion.readArrowFeather(byteArray: ByteArray, nullability: NullabilityOptions = NullabilityOptions.Infer): AnyFrame =
322322
SeekableInMemoryByteChannel(byteArray).use { readArrowFeather(it, nullability = nullability) }
323323

324324
/**
325325
* Read [Arrow random access format](https://arrow.apache.org/docs/java/ipc.html#writing-and-reading-random-access-files) data from existing [stream]
326326
*/
327-
public fun DataFrame.Companion.readArrowFeather(stream: InputStream, nullability: NullabilityOptions = NullabilityOptions.Keeping): AnyFrame =
327+
public fun DataFrame.Companion.readArrowFeather(stream: InputStream, nullability: NullabilityOptions = NullabilityOptions.Infer): AnyFrame =
328328
readArrowFeather(stream.readBytes(), nullability)
329329

330330
/**
331331
* Read [Arrow random access format](https://arrow.apache.org/docs/java/ipc.html#writing-and-reading-random-access-files) data from existing [url]
332332
*/
333-
public fun DataFrame.Companion.readArrowFeather(url: URL, nullability: NullabilityOptions = NullabilityOptions.Keeping): AnyFrame =
333+
public fun DataFrame.Companion.readArrowFeather(url: URL, nullability: NullabilityOptions = NullabilityOptions.Infer): AnyFrame =
334334
when {
335335
isFile(url) -> readArrowFeather(urlAsFile(url), nullability)
336336
isProtocolSupported(url) -> readArrowFeather(url.readBytes(), nullability)
@@ -342,7 +342,7 @@ public fun DataFrame.Companion.readArrowFeather(url: URL, nullability: Nullabili
342342
/**
343343
* Read [Arrow random access format](https://arrow.apache.org/docs/java/ipc.html#writing-and-reading-random-access-files) data from existing [path]
344344
*/
345-
public fun DataFrame.Companion.readArrowFeather(path: String, nullability: NullabilityOptions = NullabilityOptions.Keeping): AnyFrame = if (isURL(path)) {
345+
public fun DataFrame.Companion.readArrowFeather(path: String, nullability: NullabilityOptions = NullabilityOptions.Infer): AnyFrame = if (isURL(path)) {
346346
readArrowFeather(URL(path), nullability)
347347
} else {
348348
readArrowFeather(File(path), nullability)

dataframe-arrow/src/test/kotlin/ArrowKtTest.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ internal class ArrowKtTest {
3838

3939
@Test
4040
fun testReadingAllTypesAsEstimated() {
41-
assertEstimations(DataFrame.readArrowFeather(testArrowFeather("test.arrow"), NullabilityOptions.Keeping), false, false)
42-
assertEstimations(DataFrame.readArrowIPC(testArrowIPC("test.arrow"), NullabilityOptions.Keeping), false, false)
41+
assertEstimations(DataFrame.readArrowFeather(testArrowFeather("test.arrow"), NullabilityOptions.Infer), false, false)
42+
assertEstimations(DataFrame.readArrowIPC(testArrowIPC("test.arrow"), NullabilityOptions.Infer), false, false)
4343

4444
assertEstimations(DataFrame.readArrowFeather(testArrowFeather("test.arrow"), NullabilityOptions.Checking), true, false)
4545
assertEstimations(DataFrame.readArrowIPC(testArrowIPC("test.arrow"), NullabilityOptions.Checking), true, false)
@@ -50,8 +50,8 @@ internal class ArrowKtTest {
5050

5151
@Test
5252
fun testReadingAllTypesAsEstimatedWithNulls() {
53-
assertEstimations(DataFrame.readArrowFeather(testArrowFeather("test-with-nulls.arrow"), NullabilityOptions.Keeping), true, true)
54-
assertEstimations(DataFrame.readArrowIPC(testArrowIPC("test-with-nulls.arrow"), NullabilityOptions.Keeping), true, true)
53+
assertEstimations(DataFrame.readArrowFeather(testArrowFeather("test-with-nulls.arrow"), NullabilityOptions.Infer), true, true)
54+
assertEstimations(DataFrame.readArrowIPC(testArrowIPC("test-with-nulls.arrow"), NullabilityOptions.Infer), true, true)
5555

5656
assertEstimations(DataFrame.readArrowFeather(testArrowFeather("test-with-nulls.arrow"), NullabilityOptions.Checking), true, true)
5757
assertEstimations(DataFrame.readArrowIPC(testArrowIPC("test-with-nulls.arrow"), NullabilityOptions.Checking), true, true)
@@ -62,8 +62,8 @@ internal class ArrowKtTest {
6262

6363
@Test
6464
fun testReadingAllTypesAsEstimatedNotNullable() {
65-
assertEstimations(DataFrame.readArrowFeather(testArrowFeather("test-not-nullable.arrow"), NullabilityOptions.Keeping), false, false)
66-
assertEstimations(DataFrame.readArrowIPC(testArrowIPC("test-not-nullable.arrow"), NullabilityOptions.Keeping), false, false)
65+
assertEstimations(DataFrame.readArrowFeather(testArrowFeather("test-not-nullable.arrow"), NullabilityOptions.Infer), false, false)
66+
assertEstimations(DataFrame.readArrowIPC(testArrowIPC("test-not-nullable.arrow"), NullabilityOptions.Infer), false, false)
6767

6868
assertEstimations(DataFrame.readArrowFeather(testArrowFeather("test-not-nullable.arrow"), NullabilityOptions.Checking), false, false)
6969
assertEstimations(DataFrame.readArrowIPC(testArrowIPC("test-not-nullable.arrow"), NullabilityOptions.Checking), false, false)
@@ -74,8 +74,8 @@ internal class ArrowKtTest {
7474

7575
@Test
7676
fun testReadingAllTypesAsEstimatedNotNullableWithNulls() {
77-
assertEstimations(DataFrame.readArrowFeather(testArrowFeather("test-illegal.arrow"), NullabilityOptions.Keeping), true, true)
78-
assertEstimations(DataFrame.readArrowIPC(testArrowIPC("test-illegal.arrow"), NullabilityOptions.Keeping), true, true)
77+
assertEstimations(DataFrame.readArrowFeather(testArrowFeather("test-illegal.arrow"), NullabilityOptions.Infer), true, true)
78+
assertEstimations(DataFrame.readArrowIPC(testArrowIPC("test-illegal.arrow"), NullabilityOptions.Infer), true, true)
7979

8080
shouldThrow<IllegalArgumentException> {
8181
assertEstimations(DataFrame.readArrowFeather(testArrowFeather("test-illegal.arrow"), NullabilityOptions.Checking), false, true)

0 commit comments

Comments
 (0)