Skip to content

Commit e55aa2f

Browse files
committed
Back out major API change fix to query builder type promotion
1 parent 07b4d6b commit e55aa2f

File tree

3 files changed

+74
-69
lines changed

3 files changed

+74
-69
lines changed

cpp/arcticdb/processing/operation_types.hpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,11 @@ struct type_arithmetic_promoted_type {
139139
double,
140140
float
141141
>,
142-
// Otherwise, if only one type is floating point, always promote to double
143-
// For example when combining int32 and float32 the result can only fit in float64 without loss of precision
144-
// Special cases like int16 and float32 can fit in float32, but we always promote up to float64 (as does Pandas)
145-
double
142+
// Otherwise, if only one type is floating point, promote to this type
143+
std::conditional_t<std::is_floating_point_v<LHS>,
144+
LHS,
145+
RHS
146+
>
146147
>,
147148
// Otherwise, both types are integers
148149
std::conditional_t<std::is_unsigned_v<LHS> && std::is_unsigned_v<RHS>,

cpp/arcticdb/processing/test/test_arithmetic_type_promotion.cpp

+57-57
Original file line numberDiff line numberDiff line change
@@ -133,25 +133,25 @@ TEST(ArithmeticTypePromotion, Plus) {
133133
static_assert(std::is_same_v<type_arithmetic_promoted_type<int64_t, uint32_t, PlusOperator>::type, int64_t>);
134134
static_assert(std::is_same_v<type_arithmetic_promoted_type<int64_t, uint64_t, PlusOperator>::type, int64_t>);
135135
// Mixed integral and floating point types should promote to the floating point type
136-
static_assert(std::is_same_v<type_arithmetic_promoted_type<uint8_t, float, PlusOperator>::type, double>);
137-
static_assert(std::is_same_v<type_arithmetic_promoted_type<uint16_t, float, PlusOperator>::type, double>);
138-
static_assert(std::is_same_v<type_arithmetic_promoted_type<uint32_t, float, PlusOperator>::type, double>);
139-
static_assert(std::is_same_v<type_arithmetic_promoted_type<uint64_t, float, PlusOperator>::type, double>);
140-
141-
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, uint8_t, PlusOperator>::type, double>);
142-
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, uint16_t, PlusOperator>::type, double>);
143-
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, uint32_t, PlusOperator>::type, double>);
144-
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, uint64_t, PlusOperator>::type, double>);
145-
146-
static_assert(std::is_same_v<type_arithmetic_promoted_type<int8_t, float, PlusOperator>::type, double>);
147-
static_assert(std::is_same_v<type_arithmetic_promoted_type<int16_t, float, PlusOperator>::type, double>);
148-
static_assert(std::is_same_v<type_arithmetic_promoted_type<int32_t, float, PlusOperator>::type, double>);
149-
static_assert(std::is_same_v<type_arithmetic_promoted_type<int64_t, float, PlusOperator>::type, double>);
150-
151-
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, int8_t, PlusOperator>::type, double>);
152-
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, int16_t, PlusOperator>::type, double>);
153-
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, int32_t, PlusOperator>::type, double>);
154-
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, int64_t, PlusOperator>::type, double>);
136+
static_assert(std::is_same_v<type_arithmetic_promoted_type<uint8_t, float, PlusOperator>::type, float>);
137+
static_assert(std::is_same_v<type_arithmetic_promoted_type<uint16_t, float, PlusOperator>::type, float>);
138+
static_assert(std::is_same_v<type_arithmetic_promoted_type<uint32_t, float, PlusOperator>::type, float>);
139+
static_assert(std::is_same_v<type_arithmetic_promoted_type<uint64_t, float, PlusOperator>::type, float>);
140+
141+
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, uint8_t, PlusOperator>::type, float>);
142+
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, uint16_t, PlusOperator>::type, float>);
143+
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, uint32_t, PlusOperator>::type, float>);
144+
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, uint64_t, PlusOperator>::type, float>);
145+
146+
static_assert(std::is_same_v<type_arithmetic_promoted_type<int8_t, float, PlusOperator>::type, float>);
147+
static_assert(std::is_same_v<type_arithmetic_promoted_type<int16_t, float, PlusOperator>::type, float>);
148+
static_assert(std::is_same_v<type_arithmetic_promoted_type<int32_t, float, PlusOperator>::type, float>);
149+
static_assert(std::is_same_v<type_arithmetic_promoted_type<int64_t, float, PlusOperator>::type, float>);
150+
151+
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, int8_t, PlusOperator>::type, float>);
152+
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, int16_t, PlusOperator>::type, float>);
153+
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, int32_t, PlusOperator>::type, float>);
154+
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, int64_t, PlusOperator>::type, float>);
155155

156156
static_assert(std::is_same_v<type_arithmetic_promoted_type<uint8_t, double, PlusOperator>::type, double>);
157157
static_assert(std::is_same_v<type_arithmetic_promoted_type<uint16_t, double, PlusOperator>::type, double>);
@@ -262,25 +262,25 @@ TEST(ArithmeticTypePromotion, Minus) {
262262
static_assert(std::is_same_v<type_arithmetic_promoted_type<int64_t, uint32_t, MinusOperator>::type, int64_t>);
263263
static_assert(std::is_same_v<type_arithmetic_promoted_type<int64_t, uint64_t, MinusOperator>::type, int64_t>);
264264
// Mixed integral and floating point types should promote to the floating point type
265-
static_assert(std::is_same_v<type_arithmetic_promoted_type<uint8_t, float, MinusOperator>::type, double>);
266-
static_assert(std::is_same_v<type_arithmetic_promoted_type<uint16_t, float, MinusOperator>::type, double>);
267-
static_assert(std::is_same_v<type_arithmetic_promoted_type<uint32_t, float, MinusOperator>::type, double>);
268-
static_assert(std::is_same_v<type_arithmetic_promoted_type<uint64_t, float, MinusOperator>::type, double>);
269-
270-
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, uint8_t, MinusOperator>::type, double>);
271-
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, uint16_t, MinusOperator>::type, double>);
272-
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, uint32_t, MinusOperator>::type, double>);
273-
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, uint64_t, MinusOperator>::type, double>);
274-
275-
static_assert(std::is_same_v<type_arithmetic_promoted_type<int8_t, float, MinusOperator>::type, double>);
276-
static_assert(std::is_same_v<type_arithmetic_promoted_type<int16_t, float, MinusOperator>::type, double>);
277-
static_assert(std::is_same_v<type_arithmetic_promoted_type<int32_t, float, MinusOperator>::type, double>);
278-
static_assert(std::is_same_v<type_arithmetic_promoted_type<int64_t, float, MinusOperator>::type, double>);
279-
280-
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, int8_t, MinusOperator>::type, double>);
281-
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, int16_t, MinusOperator>::type, double>);
282-
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, int32_t, MinusOperator>::type, double>);
283-
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, int64_t, MinusOperator>::type, double>);
265+
static_assert(std::is_same_v<type_arithmetic_promoted_type<uint8_t, float, MinusOperator>::type, float>);
266+
static_assert(std::is_same_v<type_arithmetic_promoted_type<uint16_t, float, MinusOperator>::type, float>);
267+
static_assert(std::is_same_v<type_arithmetic_promoted_type<uint32_t, float, MinusOperator>::type, float>);
268+
static_assert(std::is_same_v<type_arithmetic_promoted_type<uint64_t, float, MinusOperator>::type, float>);
269+
270+
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, uint8_t, MinusOperator>::type, float>);
271+
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, uint16_t, MinusOperator>::type, float>);
272+
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, uint32_t, MinusOperator>::type, float>);
273+
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, uint64_t, MinusOperator>::type, float>);
274+
275+
static_assert(std::is_same_v<type_arithmetic_promoted_type<int8_t, float, MinusOperator>::type, float>);
276+
static_assert(std::is_same_v<type_arithmetic_promoted_type<int16_t, float, MinusOperator>::type, float>);
277+
static_assert(std::is_same_v<type_arithmetic_promoted_type<int32_t, float, MinusOperator>::type, float>);
278+
static_assert(std::is_same_v<type_arithmetic_promoted_type<int64_t, float, MinusOperator>::type, float>);
279+
280+
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, int8_t, MinusOperator>::type, float>);
281+
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, int16_t, MinusOperator>::type, float>);
282+
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, int32_t, MinusOperator>::type, float>);
283+
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, int64_t, MinusOperator>::type, float>);
284284

285285
static_assert(std::is_same_v<type_arithmetic_promoted_type<uint8_t, double, MinusOperator>::type, double>);
286286
static_assert(std::is_same_v<type_arithmetic_promoted_type<uint16_t, double, MinusOperator>::type, double>);
@@ -391,25 +391,25 @@ TEST(ArithmeticTypePromotion, Times) {
391391
static_assert(std::is_same_v<type_arithmetic_promoted_type<int64_t, uint32_t, TimesOperator>::type, int64_t>);
392392
static_assert(std::is_same_v<type_arithmetic_promoted_type<int64_t, uint64_t, TimesOperator>::type, int64_t>);
393393
// Mixed integral and floating point types should promote to the floating point type
394-
static_assert(std::is_same_v<type_arithmetic_promoted_type<uint8_t, float, TimesOperator>::type, double>);
395-
static_assert(std::is_same_v<type_arithmetic_promoted_type<uint16_t, float, TimesOperator>::type, double>);
396-
static_assert(std::is_same_v<type_arithmetic_promoted_type<uint32_t, float, TimesOperator>::type, double>);
397-
static_assert(std::is_same_v<type_arithmetic_promoted_type<uint64_t, float, TimesOperator>::type, double>);
398-
399-
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, uint8_t, TimesOperator>::type, double>);
400-
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, uint16_t, TimesOperator>::type, double>);
401-
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, uint32_t, TimesOperator>::type, double>);
402-
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, uint64_t, TimesOperator>::type, double>);
403-
404-
static_assert(std::is_same_v<type_arithmetic_promoted_type<int8_t, float, TimesOperator>::type, double>);
405-
static_assert(std::is_same_v<type_arithmetic_promoted_type<int16_t, float, TimesOperator>::type, double>);
406-
static_assert(std::is_same_v<type_arithmetic_promoted_type<int32_t, float, TimesOperator>::type, double>);
407-
static_assert(std::is_same_v<type_arithmetic_promoted_type<int64_t, float, TimesOperator>::type, double>);
408-
409-
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, int8_t, TimesOperator>::type, double>);
410-
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, int16_t, TimesOperator>::type, double>);
411-
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, int32_t, TimesOperator>::type, double>);
412-
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, int64_t, TimesOperator>::type, double>);
394+
static_assert(std::is_same_v<type_arithmetic_promoted_type<uint8_t, float, TimesOperator>::type, float>);
395+
static_assert(std::is_same_v<type_arithmetic_promoted_type<uint16_t, float, TimesOperator>::type, float>);
396+
static_assert(std::is_same_v<type_arithmetic_promoted_type<uint32_t, float, TimesOperator>::type, float>);
397+
static_assert(std::is_same_v<type_arithmetic_promoted_type<uint64_t, float, TimesOperator>::type, float>);
398+
399+
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, uint8_t, TimesOperator>::type, float>);
400+
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, uint16_t, TimesOperator>::type, float>);
401+
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, uint32_t, TimesOperator>::type, float>);
402+
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, uint64_t, TimesOperator>::type, float>);
403+
404+
static_assert(std::is_same_v<type_arithmetic_promoted_type<int8_t, float, TimesOperator>::type, float>);
405+
static_assert(std::is_same_v<type_arithmetic_promoted_type<int16_t, float, TimesOperator>::type, float>);
406+
static_assert(std::is_same_v<type_arithmetic_promoted_type<int32_t, float, TimesOperator>::type, float>);
407+
static_assert(std::is_same_v<type_arithmetic_promoted_type<int64_t, float, TimesOperator>::type, float>);
408+
409+
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, int8_t, TimesOperator>::type, float>);
410+
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, int16_t, TimesOperator>::type, float>);
411+
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, int32_t, TimesOperator>::type, float>);
412+
static_assert(std::is_same_v<type_arithmetic_promoted_type<float, int64_t, TimesOperator>::type, float>);
413413

414414
static_assert(std::is_same_v<type_arithmetic_promoted_type<uint8_t, double, TimesOperator>::type, double>);
415415
static_assert(std::is_same_v<type_arithmetic_promoted_type<uint16_t, double, TimesOperator>::type, double>);

python/tests/unit/arcticdb/version_store/test_column_type_changes.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,12 @@ def test_querybuilder_project_int_gt_32_float(lmdb_version_store_tiny_segment, i
269269
received.sort_index(inplace=True)
270270
expected = df
271271
expected["new_col"] = expected["col1"] + expected["col2"]
272-
# We have to promote to float64 even with 32 bit ints to avoid losing precision of the int column
272+
# We should promote to float64 even with 32 bit ints to avoid losing precision of the int column
273+
# but that will need a major release (ArcticDB 6.0.0)
274+
# Monday: 8604919374
273275
assert expected.dtypes["new_col"] == np.float64
274-
assert received.dtypes["new_col"] == np.float64
275-
assert_frame_equal(expected, received)
276+
assert received.dtypes["new_col"] == float_type
277+
assert_frame_equal(expected, received, check_dtype=False)
276278

277279

278280
@pytest.mark.parametrize("flip_addition", [True, False])
@@ -303,10 +305,12 @@ def test_querybuilder_project_int32_float32_boundary(lmdb_version_store_tiny_seg
303305
received.sort_index(inplace=True)
304306
expected = df
305307
expected["new_col"] = expected["col1"] + expected["col2"]
306-
# We have to promote to float64 even with 32 bit ints to avoid losing precision of the int column
308+
# We should promote to float64 even with int32 to avoid losing precision of the int column
309+
# but that will need a major release (ArcticDB 6.0.0)
310+
# Monday: 8604919374
307311
assert expected.dtypes["new_col"] == np.float64
308-
assert received.dtypes["new_col"] == np.float64
309-
assert_frame_equal(expected, received)
312+
assert received.dtypes["new_col"] == np.float32
313+
assert_frame_equal(expected, received, check_dtype=False)
310314

311315

312316
@pytest.mark.parametrize("integral_type", [np.int8, np.int16, np.uint8, np.uint16])
@@ -332,8 +336,8 @@ def test_querybuilder_project_int_lt_16_float(lmdb_version_store_tiny_segment, i
332336
# We could promote up to float32 without losing precision of these int types but we go all the way up to float64
333337
# to match Pandas.
334338
assert expected.dtypes["new_col"] == np.float64
335-
assert received.dtypes["new_col"] == np.float64
336-
assert_frame_equal(expected, received)
339+
assert received.dtypes["new_col"] == float_type
340+
assert_frame_equal(expected, received, check_dtype=False)
337341

338342

339343
@pytest.mark.parametrize("original_type", [np.int16, np.uint16, np.int32, np.uint32, np.int64, np.uint64])

0 commit comments

Comments
 (0)