Skip to content

Commit

Permalink
make sure filling missing values gets correct type
Browse files Browse the repository at this point in the history
  • Loading branch information
radeusgd committed Apr 19, 2023
1 parent 8d3768e commit ddb7f67
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -812,10 +812,11 @@ type Column
common_type.if_not_error <|
new_name = Naming_Helpers.function_name "fill_nothing" [self, default]
storage = self.java_column.getStorage
storage_type = Storage.from_value_type_strict common_type
new_st = case default of
Column.Value java_col ->
other_storage = java_col.getStorage
storage.fillMissingFrom other_storage
storage.fillMissingFrom other_storage storage_type
_ ->
storage.fillMissing default
col = Java_Column.new new_name new_st
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ type Operation_Type_Helpers
find_common_type_for_arguments self arguments =
types = arguments.map self.find_argument_type . filter Filter_Condition.Not_Nothing
case types.is_empty of
# TODO [RW] what to do with `x.iif Nothing Nothing`?
True -> Nothing
False -> case find_common_type types strict=True of
common_type : Value_Type -> common_type
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.enso.table.data.column.storage;

import org.enso.base.polyglot.NumericConverter;
import org.enso.table.data.column.builder.object.Builder;
import org.enso.table.data.column.builder.object.NumericBuilder;
import org.enso.table.data.column.operation.map.MapOpStorage;
Expand Down Expand Up @@ -139,7 +140,7 @@ private Storage<?> fillMissingLong(long arg) {
@Override
public Storage<?> fillMissing(Value arg) {
if (arg.isNumber()) {
if (arg.fitsInLong()) {
if (NumericConverter.isCoercibleToLong(arg.as(Object.class))) {
return fillMissingLong(arg.asLong());
} else {
return fillMissingDouble(arg.asDouble());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,11 @@ public Storage<?> fillMissing(Value arg) {
* Fills missing values in this storage, by using corresponding values from {@code other}.
*
* @param other the source of default values
* @param commonType a common type that should fit values from both storages
* @return a new storage with missing values filled
*/
public Storage<?> fillMissingFrom(Storage<?> other) {
var builder = new InferredBuilder(size());
public Storage<?> fillMissingFrom(Storage<?> other, StorageType commonType) {
var builder = Builder.getForType(commonType, size());
for (int i = 0; i < size(); i++) {
if (isNa(i)) {
builder.appendNoGrow(other.getItemBoxed(i));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,17 @@ spec setup =
decimals_filled.value_type.is_floating_point.should_be_true

Test.specify "should not allow mixing types by default" <|
table = table_builder [["X", [1, Nothing, 2, Nothing]]]
table = table_builder [["X", [1, Nothing, 2, Nothing]], ["Y", [True, False, Nothing, Nothing]], ["Z", [0.5, Nothing, Nothing, 0.25]]]
ints = table.at "X"
ints_filled = ints.fill_nothing False
ints_filled.to_vector . should_fail_with No_Common_Type
ints_filled.should_fail_with No_Common_Type

c = ints.coalesce [42.0, False]
c.to_vector . should_fail_with No_Common_Type

table.at "Y" . fill_nothing 42 . should_fail_with No_Common_Type
table.at "Z" . fill_nothing True . should_fail_with No_Common_Type

if setup.is_database.not then
Test.specify "may allow mixed types if explicitly retyped" pending="TODO: cast #6112" <|
table = table_builder [["X", [1, Nothing, 2, Nothing]]]
Expand Down

0 comments on commit ddb7f67

Please sign in to comment.