Skip to content

Commit 7679f5c

Browse files
committed
make single create_ohlc called twice
- remove create_ohlc_increase and create_ohlc_decrease - update validate_ methods so that they can be used with multiple traces when applicable
1 parent 293e518 commit 7679f5c

File tree

3 files changed

+83
-346
lines changed

3 files changed

+83
-346
lines changed

plotly/tests/test_core/test_tools/test_trace_factory.py

Lines changed: 71 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -109,23 +109,46 @@ def test_unequal_ohlc_length(self):
109109
# check: PlotlyError if open, high, low, close are not the same length
110110
# for TraceFactory.ohlc_increase and TraceFactory.ohlc_decrease
111111

112-
kwargs = {'open': [1], 'high': [1, 3], 'low': [1, 2], 'close': [1, 2]}
113-
self.assertRaises(PlotlyError, tls.TraceFactory.create_ohlc_increase,
114-
**kwargs)
115-
116-
kwargs = {'open': [1, 2], 'high': [1, 2, 3], 'low': [1, 2],
117-
'close': [1, 2]}
118-
self.assertRaises(PlotlyError, tls.TraceFactory.create_ohlc_increase,
119-
**kwargs)
120-
121-
kwargs = {'open': [1], 'high': [1, 3], 'low': [1, 2], 'close': [2]}
122-
self.assertRaises(PlotlyError, tls.TraceFactory.create_ohlc_decrease,
123-
**kwargs)
112+
kwargs = {'open': [1], 'high': [1, 3],
113+
'low': [1, 2], 'close': [1, 2],
114+
'direction': ['increasing']}
115+
self.assertRaises(PlotlyError, tls.TraceFactory.create_ohlc, **kwargs)
116+
117+
kwargs = {'open': [1, 2], 'high': [1, 2, 3],
118+
'low': [1, 2], 'close': [1, 2],
119+
'direction': ['decreasing']}
120+
self.assertRaises(PlotlyError, tls.TraceFactory.create_ohlc, **kwargs)
121+
122+
kwargs = {'open': [1, 2], 'high': [2, 3],
123+
'low': [0], 'close': [1, 3],
124+
'direction': ['increasing']}
125+
self.assertRaises(PlotlyError, tls.TraceFactory.create_ohlc, **kwargs)
126+
127+
kwargs = {'open': [1, 2], 'high': [2, 3],
128+
'low': [1, 2], 'close': [1],
129+
'direction': ['decreasing']}
130+
self.assertRaises(PlotlyError, tls.TraceFactory.create_ohlc, **kwargs)
131+
132+
def test_direction_arg(self):
133+
134+
# check: PlotlyError if direction is not defined as "increasing" or
135+
# "decreasing"
136+
137+
kwargs = {'open': [1, 4], 'high': [1, 5],
138+
'low': [1, 2], 'close': [1, 2],
139+
'direction': ['inc']}
140+
self.assertRaisesRegexp(PlotlyError,
141+
"direction must be defined as "
142+
"'increasing' or 'decreasing'",
143+
tls.TraceFactory.create_ohlc, **kwargs)
124144

125-
kwargs = {'open': [1, 2], 'high': [1, 2],
126-
'low': [1, 2, .5], 'close': [1, 2]}
127-
self.assertRaises(PlotlyError, tls.TraceFactory.create_ohlc_decrease,
128-
**kwargs)
145+
kwargs = {'open': [1, 2], 'high': [1, 3],
146+
'low': [1, 2], 'close': [1, 2],
147+
'direction': ['d']}
148+
self.assertRaisesRegexp(PlotlyError,
149+
"direction must be defined as "
150+
"'increasing' or 'decreasing'",
151+
tls.TraceFactory.create_ohlc, **kwargs)
129152

130153
def test_high_highest_value(self):
131154

@@ -135,27 +158,15 @@ def test_high_highest_value(self):
135158

136159
# create_ohlc_increase
137160
kwargs = {'open': [2, 3], 'high': [4, 2],
138-
'low': [1, 1], 'close': [1, 2]}
161+
'low': [1, 1], 'close': [1, 2],
162+
'direction': ['increasing']}
139163
self.assertRaisesRegexp(PlotlyError, "Oops! Looks like some of "
140164
"your high values are less "
141165
"the corresponding open, "
142166
"low, or close values. "
143167
"Double check that your data "
144168
"is entered in O-H-L-C order",
145-
tls.TraceFactory.create_ohlc_increase,
146-
**kwargs)
147-
148-
# create_ohlc_decrease
149-
kwargs = {'open': [2, 3], 'high': [4, 3],
150-
'low': [1, 1], 'close': [1, 6]}
151-
self.assertRaisesRegexp(PlotlyError,
152-
"Oops! Looks like some of "
153-
"your high values are less "
154-
"the corresponding open, "
155-
"low, or close values. "
156-
"Double check that your data "
157-
"is entered in O-H-L-C order",
158-
tls.TraceFactory.create_ohlc_decrease,
169+
tls.TraceFactory.create_ohlc,
159170
**kwargs)
160171

161172
def test_low_lowest_value(self):
@@ -167,38 +178,27 @@ def test_low_lowest_value(self):
167178

168179
# create_ohlc_increase
169180
kwargs = {'open': [2, 3], 'high': [4, 6],
170-
'low': [3, 1], 'close': [1, 2]}
171-
self.assertRaisesRegexp(PlotlyError,
172-
"Oops! Looks like some of "
173-
"your low values are greater "
174-
"than the corresponding high"
175-
", open, or close values. "
176-
"Double check that your data "
177-
"is entered in O-H-L-C order",
178-
tls.TraceFactory.create_ohlc_increase,
179-
**kwargs)
180-
181-
# create_ohlc_decrease
182-
kwargs = {'open': [2, 3], 'high': [4, 6],
183-
'low': [1, 5], 'close': [1, 6]}
181+
'low': [3, 1], 'close': [1, 2],
182+
'direction': ['decreasing']}
184183
self.assertRaisesRegexp(PlotlyError,
185184
"Oops! Looks like some of "
186185
"your low values are greater "
187186
"than the corresponding high"
188187
", open, or close values. "
189188
"Double check that your data "
190189
"is entered in O-H-L-C order",
191-
tls.TraceFactory.create_ohlc_decrease,
190+
tls.TraceFactory.create_ohlc,
192191
**kwargs)
193192

194193
def test_one_ohlc_increase(self):
195194

196195
# This should create one "increase" (i.e. close > open) ohlc stick
197196

198-
ohlc_incr = tls.TraceFactory.create_ohlc_increase(open=[33.0],
199-
high=[33.2],
200-
low=[32.7],
201-
close=[33.1])
197+
ohlc_incr = tls.TraceFactory.create_ohlc(open=[33.0],
198+
high=[33.2],
199+
low=[32.7],
200+
close=[33.1],
201+
direction="increasing")
202202

203203
expected_ohlc_incr = {
204204
'mode': 'lines',
@@ -215,11 +215,12 @@ def test_ohlc_increase_with_kwargs(self):
215215
# This should create one "increase" (i.e. close > open) ohlc stick
216216
# and change the name to "POSITIVE!!"
217217

218-
ohlc_incr = tls.TraceFactory.create_ohlc_increase(open=[1.5],
219-
high=[30],
220-
low=[1],
221-
close=[25],
222-
name="POSITIVE!!")
218+
ohlc_incr = tls.TraceFactory.create_ohlc(open=[1.5],
219+
high=[30],
220+
low=[1],
221+
close=[25],
222+
direction="increasing",
223+
name="POSITIVE!!")
223224

224225
expected_ohlc_incr = {
225226
'text': ('Open', 'Open', 'High', 'Low', 'Close', 'Close', ''),
@@ -236,10 +237,11 @@ def test_one_ohlc_decrease(self):
236237

237238
# This should create one "decrease" (i.e. close < open) ohlc stick
238239

239-
ohlc_decr = tls.TraceFactory.create_ohlc_decrease(open=[33.3],
240-
high=[33.3],
241-
low=[32.7],
242-
close=[32.9])
240+
ohlc_decr = tls.TraceFactory.create_ohlc(open=[33.3],
241+
high=[33.3],
242+
low=[32.7],
243+
close=[32.9],
244+
direction="decreasing")
243245

244246
expected_ohlc_decr = {
245247
'mode': 'lines',
@@ -256,11 +258,12 @@ def test_ohlc_decrease_with_kwargs(self):
256258
# This should create one "decrease" (i.e. close < open) ohlc stick
257259
# and change the line width to 4
258260

259-
ohlc_decr = tls.TraceFactory.create_ohlc_decrease(open=[15], high=[30],
260-
low=[1], close=[5],
261-
line=Line(
262-
color='rgb(214, 39, 40)',
263-
width=4))
261+
ohlc_decr = tls.TraceFactory.create_ohlc(open=[15], high=[30],
262+
low=[1], close=[5],
263+
direction="decreasing",
264+
line=Line(
265+
color='rgb(214, 39, 40)',
266+
width=4))
264267

265268
expected_ohlc_decr = {
266269
'text': ('Open', 'Open', 'High', 'Low', 'Close', 'Close', ''),
@@ -284,8 +287,10 @@ def test_ohlc_increase_and_decrease(self):
284287
l = [3, 2, 7, 3, 2, 2, 1.1, 2.3]
285288
c = [3.3, 6.3, 10, 9, 9.2, 3, 2.9, 6.1]
286289

287-
ohlc_incr = tls.TraceFactory.create_ohlc_increase(o, h, l, c)
288-
ohlc_decr = tls.TraceFactory.create_ohlc_decrease(o, h, l, c)
290+
ohlc_incr = tls.TraceFactory.create_ohlc(o, h, l, c,
291+
direction='increasing')
292+
ohlc_decr = tls.TraceFactory.create_ohlc(o, h, l, c,
293+
direction='decreasing')
289294
ohlc_data = Data([ohlc_incr, ohlc_decr])
290295

291296
expected_ohlc_data = [{

plotly/tests/test_optional/test_opt_tracefactory.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,17 @@ def test_uneven_y(self):
5353
self.assertRaises(PlotlyError, tls.TraceFactory.create_streamline,
5454
**kwargs)
5555

56-
def test_unequal_shape_u(self):
56+
def test_unequal_length_xy(self):
57+
58+
# check for PlotlyError if u and v are not the same length
59+
60+
kwargs = {'x': [0, 2, 4, 6], 'y': [1.5, 2, 3.5],
61+
'u': [[-1, -5], [-1, -5]],
62+
'v': [[1, 1], [-3, -3]]}
63+
self.assertRaises(PlotlyError, tls.TraceFactory.create_streamline,
64+
**kwargs)
65+
66+
def test_unequal_length_uv(self):
5767

5868
# check for PlotlyError if u and v are not the same length
5969

0 commit comments

Comments
 (0)