Skip to content

Commit f5f6a78

Browse files
author
Adrian Teng
committed
Fix column name check
1 parent 8c51e9f commit f5f6a78

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

arctic/store/bitemporal_store.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def update(self, symbol, data, metadata=None, upsert=True, as_of=None, **kwargs)
7878
as_of : `datetime.datetime`
7979
The "insert time". Default to datetime.now()
8080
"""
81-
if self.observe_column in data:
81+
if self.observe_column in data.index.names:
8282
raise ValueError("Column {} is not allowed as it is being used by bitemporal store interally.".format(self.observe_column))
8383
local_tz = mktz()
8484
if not as_of:
Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from datetime import datetime as dt
2-
from mock import create_autospec
2+
3+
from mock import create_autospec, sentinel
34
from pandas.util.testing import assert_frame_equal
5+
import pytest
46

57
from arctic.store.bitemporal_store import BitemporalStore
68
from tests.util import read_str_as_pandas
@@ -12,12 +14,21 @@
1214
2012-10-09 17:06:11.040 | 2.5
1315
2012-11-08 17:06:11.040 | 3.0""")
1416

17+
1518
def test_add_observe_dt_index():
16-
self = create_autospec(BitemporalStore, observe_column='col_a',
17-
sample_column='col_b')
19+
self = create_autospec(BitemporalStore, observe_column='col_a')
1820
assert_frame_equal(BitemporalStore._add_observe_dt_index(self, ts1, as_of=dt(2001, 1, 1)),
19-
read_str_as_pandas("""col_b | col_a | near
20-
2012-09-08 17:06:11.040 | 2001-01-01 | 1.0
21-
2012-10-08 17:06:11.040 | 2001-01-01 | 2.0
22-
2012-10-09 17:06:11.040 | 2001-01-01 | 2.5
23-
2012-11-08 17:06:11.040 | 2001-01-01 | 3.0""", num_index=2))
21+
read_str_as_pandas("""sample_dt | col_a | near
22+
2012-09-08 17:06:11.040 | 2001-01-01 | 1.0
23+
2012-10-08 17:06:11.040 | 2001-01-01 | 2.0
24+
2012-10-09 17:06:11.040 | 2001-01-01 | 2.5
25+
2012-11-08 17:06:11.040 | 2001-01-01 | 3.0""", num_index=2))
26+
27+
28+
def test_update_with_observe_column_fails():
29+
self = create_autospec(BitemporalStore, observe_column='col_a')
30+
with pytest.raises(ValueError) as e:
31+
BitemporalStore.update(self, sentinel.symbol, read_str_as_pandas(
32+
"""col_b | col_a | near
33+
2012-09-08 17:06:11.040 | 2001-01-01 | 1.0""", num_index=2))
34+
assert str(e.value) == "Column col_a is not allowed as it is being used by bitemporal store interally."

0 commit comments

Comments
 (0)