Skip to content

Commit

Permalink
Extend __setitem__ to ensure metadata gets refreshed for inplace chan…
Browse files Browse the repository at this point in the history
…ges (#20)

* add aggregation funcs and generalize channel output

* capitalize aggregate function in repr

* fix merge conflicts

* Extend setitem to refresh metadata and fix small bug in View repr

* add test to check inplace edits refresh metadata
  • Loading branch information
westernguy2 committed Jun 27, 2020
1 parent 3e631e2 commit 2e08396
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 19 deletions.
34 changes: 17 additions & 17 deletions examples/DatetimeDemo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"/Users/dorislee/Desktop/Research/lux/lux_stable\n"
"/Users/kunalagarwal/Desktop/lux\n"
]
}
],
Expand Down Expand Up @@ -66,7 +66,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "4c2b5acae06043cdb660f608372ef89f",
"model_id": "00200ade54954495b22d0b552e628f06",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -80,7 +80,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "94cc15eef8ed47b1b29dac7cf4a7f003",
"model_id": "4af348435df2410bb837a112f8012f1d",
"version_major": 2,
"version_minor": 0
},
Expand Down Expand Up @@ -176,7 +176,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "408364cf452e4819b1b643ba61e8655f",
"model_id": "5f5c65781d5242d28713d840928d332b",
"version_major": 2,
"version_minor": 0
},
Expand Down Expand Up @@ -248,7 +248,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"After changing the Pandas data type to datetime, we see that date field is recognized as temporal fields in Lux. (TODO: NEED FIX)"
"After changing the Pandas data type to datetime, we see that date field is recognized as temporal fields in Lux."
]
},
{
Expand All @@ -259,7 +259,7 @@
{
"data": {
"text/plain": [
"{'quantitative': ['value'], 'ordinal': [], 'nominal': ['date'], 'temporal': []}"
"{'quantitative': ['value'], 'ordinal': [], 'nominal': [], 'temporal': ['date']}"
]
},
"execution_count": 9,
Expand All @@ -279,12 +279,12 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "c3821a9c8bb442ffb5c996ff17d1f129",
"model_id": "b9a6361525bd49bdb997cd7dc01d07c9",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"LuxWidget(current_view={'config': {'view': {'continuousWidth': 400, 'continuousHeight': 300}, 'mark': {'toolti"
"LuxWidget(current_view={'config': {'view': {'continuousWidth': 400, 'continuousHeight': 300}}, 'data': {'name'"
]
},
"metadata": {},
Expand All @@ -293,7 +293,7 @@
{
"data": {
"text/plain": [
"<View (x: MEAN(value), y: date) mark: bar, score: 0.0 >"
"<View (x: date, y: MEAN(value)) mark: line, score: 0.0 >"
]
},
"execution_count": 10,
Expand Down Expand Up @@ -348,7 +348,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "3a289802484a46e08bc182dea59a2e32",
"model_id": "35378149cce541699d4e245427734e7d",
"version_major": 2,
"version_minor": 0
},
Expand Down Expand Up @@ -390,7 +390,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "ca58d144c9594c33821490fc81ab6d8a",
"model_id": "83cba17c784947939a30330a5316dac5",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -404,7 +404,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "e6b4273392e44f7e963cec18ec104c16",
"model_id": "36d5c639feba412daab7551c46d84110",
"version_major": 2,
"version_minor": 0
},
Expand Down Expand Up @@ -437,7 +437,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "6a995e86348446ad8d765d27fbb643a3",
"model_id": "d05655991365437d8d2d344a345b7701",
"version_major": 2,
"version_minor": 0
},
Expand Down Expand Up @@ -513,7 +513,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "cd45f937152a400eb355535a5d6810eb",
"model_id": "b6ca502ae41e421e81876d9fa9abbdfb",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -527,7 +527,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "6d39d46a6fec43d3b9d5dfc22ff82512",
"model_id": "b0382c8675744d209bfe7be7655ffd32",
"version_major": 2,
"version_minor": 0
},
Expand Down Expand Up @@ -566,7 +566,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "099bb067f795429892c5b4561b340060",
"model_id": "55501454e3184974892b6720300814be",
"version_major": 2,
"version_minor": 0
},
Expand Down Expand Up @@ -622,4 +622,4 @@
},
"nbformat": 4,
"nbformat_minor": 4
}
}
5 changes: 4 additions & 1 deletion lux/luxDataFrame/LuxDataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ def getContext(self):
def __repr__(self):
# TODO: _repr_ gets called from _repr_html, need to get rid of this call
return ""

def __setitem__(self, key, value):
super(LuxDataFrame, self).__setitem__(key, value)
self.computeStats()
self.computeDatasetMetadata()
#######################################################
############ Metadata: data type, model #############
#######################################################
Expand Down
2 changes: 1 addition & 1 deletion lux/view/View.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self, specLst, mark="", title=""):
self.xMinMax = {}
self.yMinMax = {}
def __repr__(self):
if not self.data:
if self.data is None:
return f"<View ({str(self.specLst)}) mark: {self.mark}, score: {self.score} >"
filter_spec = None
channels, additional_channels = [], []
Expand Down
13 changes: 13 additions & 0 deletions tests/test_dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,16 @@ def test_period_toAltair():
exportedCode = df.recommendation['Filter'][2].toAltair()

assert 'Year = 1971' in exportedCode

def test_refresh_inplace():
df = pd.DataFrame({'date': ['2020-01-01', '2020-02-01', '2020-03-01', '2020-04-01'], 'value': [10.5,15.2,20.3,25.2]})

assert df.dataType['nominal'][0] == 'date'

from lux.view.View import View
view = View(["date","value"])
view.load(df)

df['date'] = pd.to_datetime(df['date'],format="%Y-%m-%d")

assert df.dataType['temporal'][0] == 'date'

0 comments on commit 2e08396

Please sign in to comment.