Skip to content

Commit 8ed6fe6

Browse files
committed
wip extracting json module
1 parent a6e535e commit 8ed6fe6

File tree

22 files changed

+278
-132
lines changed

22 files changed

+278
-132
lines changed

build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ dependencies {
5454
api(projects.dataframeExcel)
5555
api(projects.dataframeJdbc)
5656
api(projects.dataframeCsv)
57+
api(projects.dataframeJson)
5758

5859
// experimental, so not included by default:
5960
// api(projects.dataframeOpenapi)
@@ -64,6 +65,7 @@ dependencies {
6465
kover(projects.dataframeOpenapi)
6566
kover(projects.dataframeJdbc)
6667
kover(projects.dataframeCsv)
68+
kover(projects.dataframeJson)
6769
kover(projects.plugins.kotlinDataframe)
6870
kover(projects.dataframeJupyter)
6971
}

core/build.gradle.kts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ dependencies {
6565

6666
api(libs.commonsCsv)
6767
implementation(libs.commonsIo)
68-
implementation(libs.serialization.core)
69-
implementation(libs.serialization.json)
7068
implementation(libs.fastDoubleParser)
7169

7270
api(libs.kotlin.datetimeJvm)

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/annotations/ImportDataSchema.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import org.jetbrains.kotlinx.dataframe.api.KeyValueProperty
55
import org.jetbrains.kotlinx.dataframe.columns.ColumnGroup
66
import org.jetbrains.kotlinx.dataframe.columns.FrameColumn
77
import org.jetbrains.kotlinx.dataframe.documentation.UnifyingNumbers
8-
import org.jetbrains.kotlinx.dataframe.io.JSON
98

109
/**
1110
* Annotation preprocessing will generate a DataSchema interface from the data at `path`.
@@ -73,8 +72,11 @@ public annotation class JdbcOptions(
7372
)
7473

7574
public annotation class JsonOptions(
76-
/** Allows the choice of how to handle type clashes when reading a JSON file. */
77-
public val typeClashTactic: JSON.TypeClashTactic = JSON.TypeClashTactic.ARRAY_AND_VALUE_COLUMNS,
75+
/**
76+
* Allows the choice of how to handle type clashes when reading a JSON file.
77+
* Must be either [TypeClashTactics.ARRAY_AND_VALUE_COLUMNS] or [TypeClashTactics.ANY_COLUMNS]
78+
* */
79+
public val typeClashTactic: String = TypeClashTactics.ARRAY_AND_VALUE_COLUMNS,
7880
/**
7981
* List of [JsonPath]s where instead of a [ColumnGroup], a [FrameColumn]<[KeyValueProperty]>
8082
* will be created.
@@ -85,4 +87,9 @@ public annotation class JsonOptions(
8587
public val keyValuePaths: Array<String> = [],
8688
/** Whether to [unify the numbers that are read][UnifyingNumbers]. `true` by default. */
8789
public val unifyNumbers: Boolean = true,
88-
)
90+
) {
91+
public object TypeClashTactics {
92+
public const val ARRAY_AND_VALUE_COLUMNS: String = "ARRAY_AND_VALUE_COLUMNS"
93+
public const val ANY_COLUMNS: String = "ANY_COLUMNS"
94+
}
95+
}

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ import org.jetbrains.kotlinx.dataframe.type
1515
* Creates a [FrameColumn] from [this] by splitting the dataframe into
1616
* smaller ones, with their number of rows at most [size].
1717
*/
18-
public fun <T> DataFrame<T>.chunked(size: Int, name: String = "groups"): FrameColumn<T> {
19-
val startIndices = (0 until nrow step size)
20-
return this.chunkedImpl(startIndices, name)
21-
}
18+
public fun <T> DataFrame<T>.chunked(size: Int, name: String = "groups"): FrameColumn<T> =
19+
chunked(
20+
startIndices = 0 until nrow step size,
21+
name = name,
22+
)
23+
24+
public fun <T> DataFrame<T>.chunked(startIndices: Iterable<Int>, name: String = "groups"): FrameColumn<T> =
25+
chunkedImpl(startIndices, name)
2226

2327
public fun <T> DataColumn<T>.chunked(size: Int): ValueColumn<List<T>> {
2428
val values = toList().chunked(size)

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/codeGen/DefaultReadDfMethods.kt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ private const val CAST = "cast"
2323
private const val VERIFY = "verify" // cast(true) is obscure, i think it's better to use named argument here
2424
private const val READ_CSV = "readCSV"
2525
private const val READ_TSV = "readTSV"
26-
private const val READ_JSON = "readJson"
2726
private const val READ_JDBC = "readJdbc"
2827

2928
public abstract class AbstractDefaultReadMethod(
@@ -82,13 +81,6 @@ public abstract class AbstractDefaultReadMethod(
8281
override val additionalImports: List<String> = listOf("import org.jetbrains.kotlinx.dataframe.io.$methodName")
8382
}
8483

85-
internal class DefaultReadJsonMethod(path: String?, arguments: MethodArguments) :
86-
AbstractDefaultReadMethod(
87-
path = path,
88-
arguments = arguments,
89-
methodName = READ_JSON,
90-
)
91-
9284
internal class DefaultReadCsvMethod(path: String?, arguments: MethodArguments) :
9385
AbstractDefaultReadMethod(path, arguments, READ_CSV)
9486

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/columns/ColumnGroup.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import org.jetbrains.kotlinx.dataframe.annotations.HasSchema
99
import org.jetbrains.kotlinx.dataframe.api.ColumnsSelectionDsl
1010
import org.jetbrains.kotlinx.dataframe.api.asColumnGroup
1111
import org.jetbrains.kotlinx.dataframe.api.columnGroup
12+
import org.jetbrains.kotlinx.dataframe.impl.schema.extractSchema
13+
import org.jetbrains.kotlinx.dataframe.schema.DataFrameSchema
1214
import kotlin.reflect.KProperty
1315

1416
/**

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/documentation/UnifyingNumbers.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import org.jetbrains.kotlinx.dataframe.impl.UnifiedNumberTypeOptions
2424
*
2525
* At the bottom of the graph is [Nothing]. This can be interpreted as `null`.
2626
*/
27-
internal interface UnifyingNumbers {
27+
public interface UnifyingNumbers {
2828

2929
/**
3030
* ```
@@ -47,5 +47,6 @@ internal interface UnifyingNumbers {
4747
* Nothing?
4848
* ```
4949
*/
50-
interface Graph
50+
@ExcludeFromSources
51+
private interface Graph
5152
}

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/ColumnDataCollector.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import kotlin.reflect.full.isSubclassOf
1414
import kotlin.reflect.full.withNullability
1515
import kotlin.reflect.jvm.jvmErasure
1616

17-
internal interface DataCollector<T> {
17+
public interface DataCollector<T> {
1818

1919
public val data: List<T?>
2020
public val hasNulls: Boolean

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/Utils.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ internal fun <T> catchSilent(body: () -> T): T? =
150150
internal fun Iterable<KClass<*>>.commonType(nullable: Boolean, upperBound: KType? = null) =
151151
commonParents(this).createType(nullable, upperBound)
152152

153+
// helper overload for friend modules
154+
@JvmName("commonTypeOverload")
155+
internal fun commonType(types: Iterable<KType?>, useStar: Boolean = true) =
156+
types.commonType(useStar)
157+
153158
/**
154159
* Returns the common supertype of the given types.
155160
*
@@ -276,6 +281,10 @@ internal fun <T> DataFrame<T>.splitByIndices(startIndices: Sequence<Int>): Seque
276281
}
277282
}
278283

284+
// helper overload for friend modules
285+
@JvmName("splitByIndicesOverload")
286+
internal fun <T> splitByIndices(list: List<T>, startIndices: Sequence<Int>) = list.splitByIndices(startIndices)
287+
279288
internal fun <T> List<T>.splitByIndices(startIndices: Sequence<Int>): Sequence<List<T>> =
280289
(startIndices + size).zipWithNext { start, endExclusive ->
281290
subList(start, endExclusive)

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/io/image.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,24 @@ internal fun BufferedImage.toByteArray(format: String = DEFAULT_IMG_FORMAT): Byt
5858
ImageIO.write(this, format, bos)
5959
bos.toByteArray()
6060
}
61+
62+
// helper overload for friend modules
63+
internal fun resizeKeepingAspectRatio(
64+
image: BufferedImage,
65+
maxSize: Int,
66+
resultImageType: Int = BufferedImage.TYPE_INT_ARGB,
67+
interpolation: Any = RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR,
68+
renderingQuality: Any = RenderingHints.VALUE_RENDER_QUALITY,
69+
antialiasing: Any = RenderingHints.VALUE_ANTIALIAS_ON,
70+
observer: ImageObserver? = null,
71+
) = image.resizeKeepingAspectRatio(
72+
maxSize = maxSize,
73+
resultImageType = resultImageType,
74+
interpolation = interpolation,
75+
renderingQuality = renderingQuality,
76+
antialiasing = antialiasing,
77+
observer = observer,
78+
)
79+
80+
// helper overload for friend modules
81+
internal fun toByteArray(image: BufferedImage, format: String = DEFAULT_IMG_FORMAT) = image.toByteArray(format)

0 commit comments

Comments
 (0)