Skip to content

Commit 6e06b95

Browse files
committed
wip
1 parent de82b0f commit 6e06b95

12 files changed

Lines changed: 1344 additions & 483 deletions

File tree

core/api/core.api

Lines changed: 78 additions & 40 deletions
Large diffs are not rendered by default.

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/ColumnsContainer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public interface ColumnsContainer<out T> : ColumnsScope<T> {
107107

108108
public fun <C> get(columns: ColumnsSelector<T, C>): List<DataColumn<C>>
109109

110-
public fun <C> get(column: ColumnSelector<T, C>): DataColumn<C> = get(column as ColumnsSelector<T, C>).single()
110+
public operator fun <C> get(column: ColumnSelector<T, C>): DataColumn<C> = get(column as ColumnsSelector<T, C>).single()
111111

112112
// endregion
113113
}

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

Lines changed: 300 additions & 74 deletions
Large diffs are not rendered by default.

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

Lines changed: 398 additions & 197 deletions
Large diffs are not rendered by default.

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
package org.jetbrains.kotlinx.dataframe.documentation
44

55
import org.jetbrains.kotlinx.dataframe.DataFrame
6+
import org.jetbrains.kotlinx.dataframe.api.ParserOptions
7+
import org.jetbrains.kotlinx.dataframe.api.parser
68

79
// File with KDF common KDoc-topics and -snippets.
810

@@ -40,3 +42,13 @@ internal typealias AutoRenamingLink = Nothing
4042
* does not correspond to an existing column or column group — all missing parts will be created automatically.
4143
*/
4244
internal typealias ColumnPathCreationSnippet = Nothing
45+
46+
/**
47+
* kotlinx-datetime lacks localization support: https://github.com/Kotlin/kotlinx-datetime/discussions/253.
48+
*
49+
* If you need to provide a custom [java.util.Locale], we recommend parsing
50+
* to a [java.time]-based class first before converting it to [kotlinx.datetime].
51+
*
52+
* See also: [ParserOptions], [DataFrame.parser][DataFrame.Companion.parser]
53+
*/
54+
internal typealias KotlinxDateTimeLocaleSnippet = Nothing
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
package org.jetbrains.kotlinx.dataframe.impl
2+
3+
import kotlin.collections.plusAssign
4+
5+
/**
6+
* Map that resolves values lazily.
7+
*/
8+
internal class LazyMap<K, out V>(val lazyMap: Map<K, Lazy<V>>) : Map<K, V> {
9+
10+
// Operations that traverse all values will resolve all values anyway
11+
private val resolvedMap = lazy {
12+
lazyMap.mapValues { it.value.value }
13+
}
14+
15+
override val size: Int get() = lazyMap.size
16+
override val keys: Set<K> get() = lazyMap.keys
17+
18+
// resolves all values!
19+
override val values: Collection<V> get() = resolvedMap.value.values
20+
21+
// resolves all values!
22+
override val entries: Set<Map.Entry<K, V>>
23+
get() = resolvedMap.value.entries
24+
25+
override fun isEmpty(): Boolean = lazyMap.isEmpty()
26+
27+
override fun containsKey(key: K): Boolean = lazyMap.containsKey(key)
28+
29+
// resolves as little values as possible
30+
override fun containsValue(value: @UnsafeVariance V): Boolean {
31+
if (resolvedMap.isInitialized()) {
32+
return resolvedMap.value.containsValue(value)
33+
}
34+
for (key in keys) {
35+
if (get(key) == value) return true
36+
}
37+
return false
38+
}
39+
40+
override fun get(key: K): V? =
41+
if (resolvedMap.isInitialized()) {
42+
resolvedMap.value[key]
43+
} else {
44+
lazyMap[key]?.value
45+
}
46+
}
47+
48+
/**
49+
* Creates a [Map] that resolves values lazily.
50+
*/
51+
internal fun <K, V> lazyMapOf(vararg entries: Pair<K, () -> V>): LazyMap<K, V> =
52+
LazyMap(mapOf(*entries).mapValues { lazy(it.value) })
53+
54+
///**
55+
// * Merges two maps of Iterables, appending the values from the lists in the other map
56+
// * to the lists in the first map.
57+
// */
58+
//internal infix fun <K, V> Map<K, Iterable<V>>.merge(other: Map<K, Iterable<V>>): Map<K, List<V>> =
59+
// buildMap<K, MutableList<V>> {
60+
// this@merge.forEach { (key, values) ->
61+
// this[key] = values.toMutableList()
62+
// }
63+
// other.forEach { (key, values) ->
64+
// this.getOrPut(key) { mutableListOf() } += values
65+
// }
66+
// }
67+
//
68+
///**
69+
// * Same as [Map.merge], however, it retains the laziness of the values in the first map.
70+
// */
71+
//internal infix fun <K, V> LazyMap<K, Iterable<V>>.merge(other: Map<K, Iterable<V>>): LazyMap<K, List<V>> =
72+
// LazyMap(
73+
// buildMap<K, Lazy<List<V>>> {
74+
// this@merge.lazyMap.forEach { (key, values) ->
75+
// this[key] = lazy { values.value.toList() }
76+
// }
77+
// other.forEach { (key, values) ->
78+
// if (key in this) {
79+
// this[key] = this[key]!! + values
80+
// } else {
81+
// this[key] = lazy { values.toList() }
82+
// }
83+
// }
84+
// },
85+
// )
86+
//
87+
///**
88+
// * Same as [Map.merge], however, it retains the laziness of the values in the second map.
89+
// */
90+
//internal infix fun <K, V> Map<K, Iterable<V>>.merge(other: LazyMap<K, Iterable<V>>): LazyMap<K, List<V>> =
91+
// LazyMap(
92+
// buildMap<K, Lazy<List<V>>> {
93+
// this@merge.forEach { (key, values) ->
94+
// this[key] = lazy { values.toList() }
95+
// }
96+
// other.lazyMap.forEach { (key, values) ->
97+
// if (key in this) {
98+
// this[key] = this[key]!! + values
99+
// } else {
100+
// this[key] = lazy { values.value.toList() }
101+
// }
102+
// }
103+
// },
104+
// )
105+
//
106+
///**
107+
// * Same as [Map.merge], however, it retains the laziness of the values in both maps.
108+
// */
109+
//internal infix fun <K, V> LazyMap<K, Iterable<V>>.merge(other: LazyMap<K, Iterable<V>>): LazyMap<K, List<V>> =
110+
// LazyMap(
111+
// buildMap<K, Lazy<List<V>>> {
112+
// this@merge.lazyMap.forEach { (key, values) ->
113+
// this[key] = lazy { values.value.toList() }
114+
// }
115+
// other.lazyMap.forEach { (key, values) ->
116+
// if (key in this) {
117+
// this[key] = this[key]!! + values
118+
// } else {
119+
// this[key] = lazy { values.value.toList() }
120+
// }
121+
// }
122+
// },
123+
// )
124+
//
125+
//internal operator fun <T> Lazy<Iterable<T>>.plus(other: Lazy<Iterable<T>>): Lazy<List<T>> =
126+
// lazy { this.value + other.value }
127+
//
128+
//internal operator fun <T> Lazy<Iterable<T>>.plus(other: Iterable<T>): Lazy<List<T>> = lazy { this.value + other }
129+
//
130+
//internal operator fun <T> Iterable<T>.plus(other: Lazy<Iterable<T>>): Lazy<List<T>> = lazy { this + other.value }

0 commit comments

Comments
 (0)