Skip to content

Commit 6b88486

Browse files
committed
Fix tests
1 parent b6b1b67 commit 6b88486

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

traittypes/tests/notes jeroen

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
Procedural.
2+
3+
s = IntSlider()
4+
t = Text()
5+
dlink((s, value), (d, value), foo)
6+
HBox([s, t])
7+
8+
9+
Magics!!
10+
11+
* decorator -> example with explicit code.
12+
* use of abbreviations as default values : the default values don't make sense for the function.
13+
* introspection -> explicitly give the arguments?
14+
* widget abbreviation -> explicit widget.
15+
16+
17+
* future meaningful use of abbreviations
18+
19+
def f(x : float, y : int):
20+
pass
21+
22+
interact(f)
23+
24+
* encode constraints in type annotations.
25+
26+
27+
28+
29+
30+
float -> Float -> FloatWidget
31+
def f(x = Float(min=0, max=4), y = Int()):
32+
float -> Float -> FloatWidget
33+
34+
35+
def f():
36+
37+
38+
39+
40+
thierry monteil

traittypes/traittypes.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ def __init__(self, default_value=Undefined, allow_none=False, dtype=None, **kwar
7878
self.validators = []
7979
super(Array, self).__init__(default_value=default_value, allow_none=allow_none, **kwargs)
8080

81+
def make_dynamic_default(self):
82+
if self.default_value is None:
83+
return self.default_value
84+
else:
85+
return np.copy(self.default_value)
86+
8187

8288
class DataFrame(SciType):
8389

@@ -112,6 +118,12 @@ def __init__(self, default_value=Undefined, allow_none=False, dtype=None, **kwar
112118
self.validators = []
113119
super(DataFrame, self).__init__(default_value=default_value, allow_none=allow_none, **kwargs)
114120

121+
def make_dynamic_default(self):
122+
if self.default_value is None:
123+
return self.default_value
124+
else:
125+
return self.default_value.copy()
126+
115127

116128
class Series(SciType):
117129

@@ -145,3 +157,9 @@ def __init__(self, default_value=Undefined, allow_none=False, dtype=None, **kwar
145157
default_value = pd.Series(default_value)
146158
self.validators = []
147159
super(Series, self).__init__(default_value=default_value, allow_none=allow_none, **kwargs)
160+
161+
def make_dynamic_default(self):
162+
if self.default_value is None:
163+
return self.default_value
164+
else:
165+
return self.default_value.copy()

0 commit comments

Comments
 (0)