|
12 | 12 | InternalException,
|
13 | 13 | NormalizationException,
|
14 | 14 | SortingException,
|
| 15 | + SchemaException |
15 | 16 | )
|
16 | 17 | from arcticdb_ext import set_config_int
|
17 | 18 | from arcticdb.util.test import random_integers, assert_frame_equal
|
@@ -673,3 +674,51 @@ def test_defragment_no_work_to_do(sym, lmdb_version_store):
|
673 | 674 | assert list(lmdb_version_store.list_versions(sym))[0]["version"] == 0
|
674 | 675 | with pytest.raises(InternalException):
|
675 | 676 | lmdb_version_store.defragment_symbol_data(sym)
|
| 677 | + |
| 678 | +@pytest.mark.parametrize("to_write, to_append", [ |
| 679 | + (pd.DataFrame({"a": [1]}), pd.Series([2])), |
| 680 | + (pd.DataFrame({"a": [1]}), np.array([2])), |
| 681 | + (pd.Series([1]), pd.DataFrame({"a": [2]})), |
| 682 | + (pd.Series([1]), np.array([2])), |
| 683 | + (np.array([1]), pd.DataFrame({"a": [2]})), |
| 684 | + (np.array([1]), pd.Series([2])), |
| 685 | + (pd.DataFrame({"a": [1], "b": [2]}), pd.Series([2])), |
| 686 | + (pd.DataFrame({"a": [1], "b": [2]}), np.array([2])), |
| 687 | + (pd.Series([1]), pd.DataFrame({"a": [2], "b": [2]})), |
| 688 | + (np.array([1]), pd.DataFrame({"a": [2], "b": [2]})) |
| 689 | +]) |
| 690 | +def test_append_mismatched_object_kind(to_write, to_append, lmdb_version_store_dynamic_schema_v1): |
| 691 | + lib = lmdb_version_store_dynamic_schema_v1 |
| 692 | + lib.write("sym", to_write) |
| 693 | + with pytest.raises(NormalizationException) as e: |
| 694 | + lib.append("sym", to_append) |
| 695 | + assert "Append" in str(e.value) |
| 696 | + |
| 697 | +@pytest.mark.parametrize("to_write, to_append", [ |
| 698 | + (pd.Series([1, 2, 3], name="name_1"), pd.Series([4, 5, 6], name="name_2")), |
| 699 | + ( |
| 700 | + pd.Series([1, 2, 3], name="name_1", index=pd.DatetimeIndex([pd.Timestamp(0), pd.Timestamp(1), pd.Timestamp(2)])), |
| 701 | + pd.Series([4, 5, 6], name="name_2", index=pd.DatetimeIndex([pd.Timestamp(3), pd.Timestamp(4), pd.Timestamp(5)])) |
| 702 | + ) |
| 703 | +]) |
| 704 | +def test_append_series_with_different_column_name_throws(lmdb_version_store_dynamic_schema_v1, to_write, to_append): |
| 705 | + # It makes sense to create a new column and turn the whole thing into a dataframe. This would require changes in the |
| 706 | + # logic for storing normalization metadata which is tricky. Noone has requested this, so we just throw. |
| 707 | + lib = lmdb_version_store_dynamic_schema_v1 |
| 708 | + lib.write("sym", to_write) |
| 709 | + with pytest.raises(SchemaException) as e: |
| 710 | + lib.append("sym", to_append) |
| 711 | + assert "name_1" in str(e.value) and "name_2" in str(e.value) |
| 712 | + |
| 713 | +def test_append_series_with_different_row_range_index_name(lmdb_version_store_dynamic_schema_v1): |
| 714 | + lib = lmdb_version_store_dynamic_schema_v1 |
| 715 | + to_write = pd.Series([1, 2, 3]) |
| 716 | + to_write.index.name = "index_name_1" |
| 717 | + to_append = pd.Series([4, 5, 6]) |
| 718 | + to_append.index.name = "index_name_2" |
| 719 | + lib.write("sym", to_write) |
| 720 | + lib.append("sym", to_append) |
| 721 | + # The current behavior is the last modification operation is setting the index name. |
| 722 | + # See Monday 9797097831, it would be best to require that index names are always matching. This is the case for |
| 723 | + # datetime index because it's a physical column. It's a potentially breaking change. |
| 724 | + assert lib.read("sym").data.index.name == "index_name_2" |
0 commit comments