nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: altair-viz/altair
Pull request #265 (2016-11-09 23:30:36)

BUG: respect empty strings as trait values
addresses #264


Patch:
diff --git a/altair/api.py b/altair/api.py
index ec7f5602..bb86bffb 100644
--- a/altair/api.py
+++ b/altair/api.py
@@ -78,7 +78,8 @@ def use_signature(Obj):
 # - allows expr trait to be an Expression and processes it properly
 #*************************************************************************
 class Formula(schema.Formula):
-    expr = T.Union([T.Unicode(), T.Instance(expr.Expression)],
+    expr = T.Union([T.Unicode(allow_none=True, default_value=None),
+                    T.Instance(expr.Expression)],
                     allow_none=True, default_value=None,
                     help=schema.Formula.expr.help)
 
@@ -97,7 +98,7 @@ class Formula(schema.Formula):
 # - allows filter trait to be an Expression and processes it properly
 #*************************************************************************
 class Transform(schema.Transform):
-    filter = T.Union([T.Unicode(),
+    filter = T.Union([T.Unicode(allow_none=True, default_value=None),
                       T.Instance(expr.Expression),
                       T.Instance(schema.EqualFilter),
                       T.Instance(schema.RangeFilter),
diff --git a/altair/schema/baseobject.py b/altair/schema/baseobject.py
index ac7fddd0..22337bf0 100644
--- a/altair/schema/baseobject.py
+++ b/altair/schema/baseobject.py
@@ -116,7 +116,7 @@ class BaseObject(T.HasTraits):
         if isinstance(value, pd.DataFrame):
             return True
         elif value is not None:
-            if isinstance(value, (int, float, bool)):
+            if isinstance(value, (int, float, bool, string_types)):
                 return True
             else:
                 return bool(value)


Test patch:
diff --git a/altair/tests/test_api.py b/altair/tests/test_api.py
index 76376b04..8f32cdcd 100644
--- a/altair/tests/test_api.py
+++ b/altair/tests/test_api.py
@@ -540,3 +540,13 @@ def test_chart_dir():
     assert 'mark' in chart
     assert 'layers' in layerchart
     assert 'facet' in facetchart
+
+
+def test_empty_traits():
+    # regression test for #264
+    axis = Axis(title='')
+    assert axis.to_dict() == {'title': ''}
+
+    # regression test for changes in #265
+    assert Transform().to_dict() == {}  # filter not present
+    assert Formula('blah').to_dict() == {'field': 'blah'}  # expr not present