@@ -12,7 +12,6 @@ import org.jetbrains.kotlinx.dataframe.schema.ComparisonMode.STRICT
1212import org.jetbrains.kotlinx.dataframe.schema.ComparisonMode.STRICT_FOR_NESTED_SCHEMAS
1313import org.jetbrains.kotlinx.dataframe.schema.DataFrameSchema
1414import org.jetbrains.kotlinx.dataframe.schema.plus
15- import kotlin.collections.forEach
1615
1716public class DataFrameSchemaImpl (override val columns : Map <String , ColumnSchema >) : DataFrameSchema {
1817
@@ -54,11 +53,47 @@ public class DataFrameSchemaImpl(override val columns: Map<String, ColumnSchema>
5453 return result
5554 }
5655
57- override fun equals (other : Any? ): Boolean = other is DataFrameSchema && this .compare(other).isEqual()
56+ /* *
57+ * Returns `true` if, and only if,
58+ * [this schema][this] has the same columns **in the same order** as the [other schema][other].
59+ * The types must also match exactly.
60+ *
61+ * Use [compare][DataFrameSchema.compare] it the order does not matter and
62+ * for other comparison options.
63+ *
64+ * @see [DataFrameSchema.compare]
65+ * @see [CompareResult.matches]
66+ */
67+ override fun equals (other : Any? ): Boolean {
68+ if (this == = other) return true
69+ if (other !is DataFrameSchema ) return false
70+ if (this .compare(other) != Matches ) return false
71+ if (columns.keys.toList() != other.columns.keys.toList()) return false
72+
73+ for ((name, col) in columns) {
74+ val other = other.columns[name]!!
75+ when (col) {
76+ is ColumnSchema .Group -> {
77+ other as ColumnSchema .Group // safe to cast because of compare
78+ if (col.schema != other.schema) return false
79+ }
80+
81+ is ColumnSchema .Frame -> {
82+ other as ColumnSchema .Frame // safe to cast because of compare
83+ if (col.schema != other.schema) return false
84+ }
85+
86+ // already checked by compare
87+ is ColumnSchema .Value -> Unit
88+ }
89+ }
90+
91+ return true
92+ }
5893
5994 override fun toString (): String = render()
6095
61- override fun hashCode (): Int = columns.hashCode()
96+ override fun hashCode (): Int = columns.toList(). hashCode()
6297}
6398
6499internal fun DataFrameSchemaImpl.render (): String {
0 commit comments