@@ -6,7 +6,6 @@ import org.jetbrains.kotlinx.dataframe.api.cast
66import  org.jetbrains.kotlinx.dataframe.api.concat 
77import  org.jetbrains.kotlinx.dataframe.api.filter 
88import  org.jetbrains.kotlinx.dataframe.api.map 
9- import  org.jetbrains.kotlinx.dataframe.api.schema 
109import  org.jetbrains.kotlinx.dataframe.api.take 
1110import  org.jetbrains.kotlinx.dataframe.columns.BaseColumn 
1211import  org.jetbrains.kotlinx.dataframe.columns.ColumnGroup 
@@ -15,16 +14,28 @@ import org.jetbrains.kotlinx.dataframe.columns.ColumnPath
1514import  org.jetbrains.kotlinx.dataframe.columns.ColumnResolutionContext 
1615import  org.jetbrains.kotlinx.dataframe.columns.ColumnWithPath 
1716import  org.jetbrains.kotlinx.dataframe.columns.FrameColumn 
17+ import  org.jetbrains.kotlinx.dataframe.columns.TypeSuggestion 
1818import  org.jetbrains.kotlinx.dataframe.columns.ValueColumn 
19+ import  org.jetbrains.kotlinx.dataframe.impl.api.chunkedImpl 
1920import  org.jetbrains.kotlinx.dataframe.impl.columns.ColumnGroupImpl 
2021import  org.jetbrains.kotlinx.dataframe.impl.columns.FrameColumnImpl 
2122import  org.jetbrains.kotlinx.dataframe.impl.columns.ValueColumnImpl 
2223import  org.jetbrains.kotlinx.dataframe.impl.columns.addPath 
23- import  org.jetbrains.kotlinx.dataframe.impl.columns.guessColumnType  
24+ import  org.jetbrains.kotlinx.dataframe.impl.columns.createColumnGuessingType  
2425import  org.jetbrains.kotlinx.dataframe.impl.columns.toColumnKind 
2526import  org.jetbrains.kotlinx.dataframe.impl.getValuesType 
26- import  org.jetbrains.kotlinx.dataframe.impl.splitByIndices 
2727import  org.jetbrains.kotlinx.dataframe.schema.DataFrameSchema 
28+ import  org.jetbrains.kotlinx.dataframe.util.CHUNKED_IMPL_IMPORT 
29+ import  org.jetbrains.kotlinx.dataframe.util.CREATE 
30+ import  org.jetbrains.kotlinx.dataframe.util.CREATE_BY_INFERENCE_IMPORT 
31+ import  org.jetbrains.kotlinx.dataframe.util.CREATE_BY_TYPE_IMPORT 
32+ import  org.jetbrains.kotlinx.dataframe.util.CREATE_FRAME_COLUMN 
33+ import  org.jetbrains.kotlinx.dataframe.util.CREATE_FRAME_COLUMN_REPLACE 
34+ import  org.jetbrains.kotlinx.dataframe.util.CREATE_INLINE_REPLACE 
35+ import  org.jetbrains.kotlinx.dataframe.util.CREATE_REPLACE 
36+ import  org.jetbrains.kotlinx.dataframe.util.CREATE_WITH_TYPE_INFERENCE 
37+ import  org.jetbrains.kotlinx.dataframe.util.CREATE_WITH_TYPE_INFERENCE_REPLACE 
38+ import  org.jetbrains.kotlinx.dataframe.util.TYPE_SUGGESTION_IMPORT 
2839import  kotlin.reflect.KClass 
2940import  kotlin.reflect.KProperty 
3041import  kotlin.reflect.KType 
@@ -45,6 +56,9 @@ public interface DataColumn<out T> : BaseColumn<T> {
4556        /* *
4657         * Creates [ValueColumn] using given [name], [values] and [type]. 
4758         * 
59+          * Be careful; values are NOT checked to adhere to [type] for efficiency, 
60+          * unless you specify [infer]. 
61+          * 
4862         * @param name name of the column 
4963         * @param values list of column values 
5064         * @param type type of the column 
@@ -56,12 +70,20 @@ public interface DataColumn<out T> : BaseColumn<T> {
5670            type :  KType ,
5771            infer :  Infer  = Infer .None ,
5872            defaultValue :  T ?  = null,
59-         ): ValueColumn <T > =  ValueColumnImpl (values, name, getValuesType(values, type, infer), defaultValue)
73+         ): ValueColumn <T > = 
74+             ValueColumnImpl (
75+                 values =  values,
76+                 name =  name,
77+                 type =  getValuesType(values, type, infer),
78+                 defaultValue =  defaultValue,
79+             )
6080
6181        /* *
6282         * Creates [ValueColumn] using given [name], [values] and reified column [type]. 
6383         * 
64-          * Note, that column [type] will be defined at compile-time using [T] argument 
84+          * The column [type] will be defined at compile-time using [T] argument. 
85+          * Be careful with casting; values are NOT checked to adhere to `reified` type [T] for efficiency, 
86+          * unless you specify [infer]. 
6587         * 
6688         * @param T type of the column 
6789         * @param name name of the column 
@@ -74,48 +96,187 @@ public interface DataColumn<out T> : BaseColumn<T> {
7496            infer :  Infer  = Infer .None ,
7597        ): ValueColumn <T > = 
7698            createValueColumn(
77-                 name,
78-                 values,
79-                 getValuesType(
80-                     values,
81-                     typeOf<T >(),
82-                     infer,
83-                 ),
99+                 name =  name,
100+                 values =  values,
101+                 type =  typeOf<T >(),
102+                 infer =  infer,
84103            )
85104
105+         /* *
106+          * Creates [ColumnGroup] using the given [name] and [df] representing the group of columns. 
107+          * 
108+          * @param name name of the column group 
109+          * @param df the collection of columns representing the column group 
110+          */  
86111        public  fun  <T > createColumnGroup (name :  String , df :  DataFrame <T >): ColumnGroup <T > =  ColumnGroupImpl (name, df)
87112
88-         public  fun  <T > createFrameColumn (name :  String , df :  DataFrame <T >, startIndices :  Iterable <Int >): FrameColumn <T > = 
89-             FrameColumnImpl (name, df.splitByIndices(startIndices.asSequence()).toList(), lazy { df.schema() })
90- 
113+         /* *
114+          * Creates [FrameColumn] using the given [name] and list of dataframes [groups]. 
115+          * 
116+          * [groups] must be a non-null list of [DataFrames][DataFrame], as [FrameColumn] does 
117+          * not allow `null` values. 
118+          * This is NOT checked at runtime for efficiency, nor is the validity of given [schema]. 
119+          * 
120+          * @param name name of the frame column 
121+          * @param groups the dataframes to be put in the column 
122+          * @param schema an optional (lazily calculated) [DataFrameSchema] representing 
123+          *   the intersecting schema of [groups] 
124+          */  
91125        public  fun  <T > createFrameColumn (
92126            name :  String ,
93127            groups :  List <DataFrame <T >>,
94128            schema :  Lazy <DataFrameSchema >?  = null,
95129        ): FrameColumn <T > =  FrameColumnImpl (name, groups, schema)
96130
97-         public  fun  <T > createWithTypeInference (
131+         /* *
132+          * Creates either a [FrameColumn], [ColumnGroup], or [ValueColumn] by analyzing each value in 
133+          * [values]. 
134+          * 
135+          * This is safer but slower than the other functions. 
136+          * 
137+          * Some conversions are done automatically to attempt to unify the values. 
138+          * 
139+          * For instance, when there are other [DataFrames][DataFrame] present in [values], we'll convert: 
140+          * - `null` -> [DataFrame.empty]`()` 
141+          * - [DataRow] -> single-row [DataFrame] 
142+          * - [List][List]`<`[DataRow][DataRow]`<*>>` -> multi-row [DataFrame] 
143+          * 
144+          * to be able to create a [FrameColumn]. 
145+          * There are more conversions for other types as well. 
146+          * 
147+          * @param name name of the column 
148+          * @param values the values to represent each row in the column 
149+          * @param suggestedType optional suggested type for values. Default is [TypeSuggestion.Infer]. 
150+          *   See [TypeSuggestion] for more information. 
151+          * @param nullable optionally you can specify whether [values] contains nulls, if `null` it is inferred. 
152+          */  
153+         public  fun  <T > createByInference (
98154            name :  String ,
99155            values :  List <T >,
156+             suggestedType :  TypeSuggestion  = TypeSuggestion .Infer ,
100157            nullable :  Boolean?  = null,
101-         ): DataColumn <T > =  guessColumnType(name, values, nullable =  nullable)
158+         ): DataColumn <T > = 
159+             createColumnGuessingType(
160+                 name =  name,
161+                 values =  values,
162+                 suggestedType =  suggestedType,
163+                 nullable =  nullable,
164+             )
102165
103-         public  fun  <T > create (
166+         /* *
167+          * Calls [createColumnGroup], [createFrameColumn], or [createValueColumn] based on 
168+          * [type]. 
169+          * 
170+          * This may be unsafe but is more efficient than [createByInference]. 
171+          * 
172+          * Be careful; Values in [values] are NOT checked to adhere to the given [type], nor 
173+          * do we check whether there are unexpected nulls among the values. 
174+          * 
175+          * It's recommended to use [createValueColumn], [createColumnGroup], and [createFrameColumn] instead. 
176+          * 
177+          * @param name the name of the column 
178+          * @param values the values to represent each row in the column 
179+          * @param type the (unchecked) common type of [values] 
180+          * @param infer in case a [ValueColumn] is created, this controls how/whether types need to be inferred 
181+          */  
182+         public  fun  <T > createByType (
104183            name :  String ,
105184            values :  List <T >,
106185            type :  KType ,
107186            infer :  Infer  = Infer .None ,
108187        ): DataColumn <T > = 
109-             when  (type.toColumnKind()) {
188+             when  (type.toColumnKind()) {  //  AnyFrame -> Frame, AnyRow? -> Group, else -> Value 
110189                ColumnKind .Value  ->  createValueColumn(name, values, type, infer)
190+ 
111191                ColumnKind .Group  ->  createColumnGroup(name, (values as  List <AnyRow ?>).concat()).asDataColumn().cast()
192+ 
112193                ColumnKind .Frame  ->  createFrameColumn(name, values as  List <AnyFrame >).asDataColumn().cast()
113194            }
114195
115-         public  inline  fun  <reified  T > create (name :  String , values :  List <T >, infer :  Infer  = Infer .None ): DataColumn <T > = 
116-             create(name, values, typeOf<T >(), infer)
196+         /* *
197+          * Calls [createColumnGroup], [createFrameColumn], or [createValueColumn] based on 
198+          * type [T]. 
199+          * 
200+          * This is generally safe, as [T] can be inferred by the compiler, 
201+          * and more efficient than [createByInference]. 
202+          * 
203+          * Be careful when casting occurs; Values in [values] are NOT checked to adhere to the given/inferred type [T], 
204+          * nor do we check whether there are unexpected nulls among the values. 
205+          * 
206+          * It's recommended to use [createValueColumn], [createColumnGroup], and [createFrameColumn] instead. 
207+          * 
208+          * @param T the (unchecked) common type of [values] 
209+          * @param name the name of the column 
210+          * @param values the values to represent each row in the column 
211+          * @param infer in case a [ValueColumn] is created, this controls how/whether types need to be inferred 
212+          */  
213+         public  inline  fun  <reified  T > createByType (
214+             name :  String ,
215+             values :  List <T >,
216+             infer :  Infer  = Infer .None ,
217+         ): DataColumn <T > =  createByType(name, values, typeOf<T >(), infer)
117218
219+         /* * Creates an empty [DataColumn] with given [name]. */ 
118220        public  fun  empty (name :  String  = ""): AnyCol  =  createValueColumn(name, emptyList<Unit >(), typeOf<Unit >())
221+ 
222+         //  region deprecated
223+ 
224+         @Deprecated(
225+             message =  CREATE_FRAME_COLUMN ,
226+             replaceWith =  ReplaceWith (CREATE_FRAME_COLUMN_REPLACE , CHUNKED_IMPL_IMPORT ),
227+             level =  DeprecationLevel .WARNING ,
228+         )
229+         public  fun  <T > createFrameColumn (name :  String , df :  DataFrame <T >, startIndices :  Iterable <Int >): FrameColumn <T > = 
230+             df.chunkedImpl(startIndices =  startIndices, name =  name)
231+ 
232+         @Deprecated(
233+             message =  CREATE_WITH_TYPE_INFERENCE ,
234+             replaceWith =  ReplaceWith (
235+                 CREATE_WITH_TYPE_INFERENCE_REPLACE ,
236+                 CREATE_BY_INFERENCE_IMPORT ,
237+                 TYPE_SUGGESTION_IMPORT ,
238+             ),
239+             level =  DeprecationLevel .WARNING ,
240+         )
241+         public  fun  <T > createWithTypeInference (
242+             name :  String ,
243+             values :  List <T >,
244+             nullable :  Boolean?  = null,
245+         ): DataColumn <T > = 
246+             createByInference(
247+                 name =  name,
248+                 values =  values,
249+                 suggestedType =  TypeSuggestion .Infer ,
250+                 nullable =  nullable,
251+             )
252+ 
253+         @Deprecated(
254+             message =  CREATE ,
255+             replaceWith =  ReplaceWith (CREATE_REPLACE , CREATE_BY_TYPE_IMPORT ),
256+             level =  DeprecationLevel .WARNING ,
257+         )
258+         public  fun  <T > create (
259+             name :  String ,
260+             values :  List <T >,
261+             type :  KType ,
262+             infer :  Infer  = Infer .None ,
263+         ): DataColumn <T > = 
264+             createByType(
265+                 name =  name,
266+                 values =  values,
267+                 type =  type,
268+                 infer =  infer,
269+             )
270+ 
271+         @Deprecated(
272+             message =  CREATE ,
273+             replaceWith =  ReplaceWith (CREATE_INLINE_REPLACE , CREATE_BY_TYPE_IMPORT ),
274+             level =  DeprecationLevel .WARNING ,
275+         )
276+         public  inline  fun  <reified  T > create (name :  String , values :  List <T >, infer :  Infer  = Infer .None ): DataColumn <T > = 
277+             createByType(name =  name, values =  values, type =  typeOf<T >(), infer =  infer)
278+ 
279+         //  endregion
119280    }
120281
121282    public  fun  hasNulls (): Boolean  =  type().isMarkedNullable
0 commit comments