Skip to content

First PR for Gantt Charts - Adding Tests Very Soon #460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
Jun 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0eeae61
First PR for Gantt Charts - Adding Tests Very Soon
Kully May 16, 2016
fe67a2b
Added Doc Strings and Tests
Kully May 17, 2016
e228307
made range(len(tasks)) into a list for Python 3
Kully May 17, 2016
e7a1596
Added colorbar visibility on the side of chart
Kully May 17, 2016
3035dba
Made Gantt Changes
Kully May 31, 2016
675ba7d
More stuff
Kully May 31, 2016
29dbb44
updated unlabel_rgb
Kully May 31, 2016
6671106
gantt//update old parsing functions//tests
Kully May 31, 2016
7ac7d9b
Updated schema
Kully May 31, 2016
f165b73
Updated tests
Kully Jun 1, 2016
00f8162
Rewrote tests in core and optional
Kully Jun 2, 2016
66382e2
added colors dictionary option
Kully Jun 2, 2016
86f61bc
Added dictionary compatibility to colors/fixed doc strings
Kully Jun 2, 2016
abff982
REQ to REQUIRED
Kully Jun 3, 2016
e6aa0e4
trace attempts
Kully Jun 3, 2016
3b75d48
Merged master into Gantt
Kully Jun 15, 2016
cfa066e
Added color_parser functionality in create_gantt
Kully Jun 15, 2016
ba65217
Added legend support for gantt charts and added more tests
Kully Jun 17, 2016
9e52ce4
Added dataframe all_args test for gantt//various formatting
Kully Jun 17, 2016
ac64ff3
added self.maxDiff=None
Kully Jun 17, 2016
b28f040
Switch to assertequaldict in test
Kully Jun 18, 2016
866f5c9
Another one
Kully Jun 18, 2016
2142397
test 'shapes' in 'layout' only
Kully Jun 18, 2016
bfbe24c
just test data
Kully Jun 18, 2016
afd45a1
Redo test
Kully Jun 18, 2016
3ac0da4
try again
Kully Jun 18, 2016
0ab3ad1
again
Kully Jun 18, 2016
a7be116
Fixed formatting
Kully Jun 18, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
240 changes: 240 additions & 0 deletions plotly/tests/test_core/test_tools/test_figure_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -1125,6 +1125,246 @@ def test_table_with_index(self):
'zeroline': False}}}
self.assertEqual(index_table, exp_index_table)


class TestGantt(TestCase):

def test_validate_gantt(self):

# validate the basic gantt inputs

df = [{'Task': 'Job A',
'Start': '2009-02-01',
'Finish': '2009-08-30',
'Complete': 'a'}]

pattern2 = ('In order to use an indexing column and assign colors to '
'the values of the index, you must choose an actual '
'column name in the dataframe or key if a list of '
'dictionaries is being used.')

self.assertRaisesRegexp(PlotlyError, pattern2,
tls.FigureFactory.create_gantt,
df, index_col='foo')

df = 'foo'

pattern3 = ('You must input either a dataframe or a list of '
'dictionaries.')

self.assertRaisesRegexp(PlotlyError, pattern3,
tls.FigureFactory.create_gantt, df)

df = []

pattern4 = ('Your list is empty. It must contain at least one '
'dictionary.')

self.assertRaisesRegexp(PlotlyError, pattern4,
tls.FigureFactory.create_gantt, df)

df = ['foo']

pattern5 = ('Your list must only include dictionaries.')

self.assertRaisesRegexp(PlotlyError, pattern5,
tls.FigureFactory.create_gantt, df)

def test_gantt_index(self):

# validate the index used for gantt

df = [{'Task': 'Job A',
'Start': '2009-02-01',
'Finish': '2009-08-30',
'Complete': 50}]

pattern = ('In order to use an indexing column and assign colors to '
'the values of the index, you must choose an actual '
'column name in the dataframe or key if a list of '
'dictionaries is being used.')

self.assertRaisesRegexp(PlotlyError, pattern,
tls.FigureFactory.create_gantt,
df, index_col='foo')

df = [{'Task': 'Job A', 'Start': '2009-02-01',
'Finish': '2009-08-30', 'Complete': 'a'},
{'Task': 'Job A', 'Start': '2009-02-01',
'Finish': '2009-08-30', 'Complete': 50}]

pattern2 = ('Error in indexing column. Make sure all entries of each '
'column are all numbers or all strings.')

self.assertRaisesRegexp(PlotlyError, pattern2,
tls.FigureFactory.create_gantt,
df, index_col='Complete')

def test_gantt_validate_colors(self):

# validate the gantt colors variable

df = [{'Task': 'Job A', 'Start': '2009-02-01',
'Finish': '2009-08-30', 'Complete': 75, 'Resource': 'A'},
{'Task': 'Job B', 'Start': '2009-02-01',
'Finish': '2009-08-30', 'Complete': 50, 'Resource': 'B'}]

pattern = ('Whoops! The elements in your rgb colors tuples cannot '
'exceed 255.0.')

self.assertRaisesRegexp(PlotlyError, pattern,
tls.FigureFactory.create_gantt, df,
index_col='Complete', colors='rgb(300,1,1)')

self.assertRaises(PlotlyError, tls.FigureFactory.create_gantt,
df, index_col='Complete', colors='foo')

pattern2 = ('Whoops! The elements in your colors tuples cannot '
'exceed 1.0.')

self.assertRaisesRegexp(PlotlyError, pattern2,
tls.FigureFactory.create_gantt, df,
index_col='Complete', colors=(2, 1, 1))

# verify that if colors is a dictionary, its keys span all the
# values in the index column
colors_dict = {75: 'rgb(1, 2, 3)'}

pattern3 = ('If you are using colors as a dictionary, all of its '
'keys must be all the values in the index column.')

self.assertRaisesRegexp(PlotlyError, pattern3,
tls.FigureFactory.create_gantt, df,
index_col='Complete', colors=colors_dict)

# check: index is set if colors is a dictionary
colors_dict_good = {50: 'rgb(1, 2, 3)', 75: 'rgb(5, 10, 15)'}

pattern4 = ('Error. You have set colors to a dictionary but have not '
'picked an index. An index is required if you are '
'assigning colors to particular values in a dictioanry.')

self.assertRaisesRegexp(PlotlyError, pattern4,
tls.FigureFactory.create_gantt, df,
colors=colors_dict_good)

# check: number of colors is equal to or greater than number of
# unique index string values
pattern5 = ("Error. The number of colors in 'colors' must be no less "
"than the number of unique index values in your group "
"column.")

self.assertRaisesRegexp(PlotlyError, pattern5,
tls.FigureFactory.create_gantt, df,
index_col='Resource',
colors=['#ffffff'])

# check: if index is numeric, colors has at least 2 colors in it
pattern6 = ("You must use at least 2 colors in 'colors' if you "
"are using a colorscale. However only the first two "
"colors given will be used for the lower and upper "
"bounds on the colormap.")

self.assertRaisesRegexp(PlotlyError, pattern6,
tls.FigureFactory.create_gantt, df,
index_col='Complete',
colors=['#ffffff'])

def test_gantt_all_args(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great test!


# check if gantt chart matches with expected output

df = [{'Task': 'Run',
'Start': '2010-01-01',
'Finish': '2011-02-02',
'Complete': 0},
{'Task': 'Fast',
'Start': '2011-01-01',
'Finish': '2012-06-05',
'Complete': 25}]

test_gantt_chart = tls.FigureFactory.create_gantt(
df, colors='Blues', index_col='Complete', reverse_colors=True,
title='Title', bar_width=0.5, showgrid_x=True, showgrid_y=True,
height=500, width=500
)

exp_gantt_chart = {
'data': [{'marker': {'color': 'white'},
'name': '',
'x': ['2010-01-01', '2011-02-02'],
'y': [0, 0]},
{'marker': {'color': 'white'},
'name': '',
'x': ['2011-01-01', '2012-06-05'],
'y': [1, 1]}],
'layout': {'height': 500,
'hovermode': 'closest',
'shapes': [{'fillcolor': 'rgb(220.0, 220.0, 220.0)',
'line': {'width': 0},
'opacity': 1,
'type': 'rect',
'x0': '2010-01-01',
'x1': '2011-02-02',
'xref': 'x',
'y0': -0.5,
'y1': 0.5,
'yref': 'y'},
{'fillcolor': 'rgb(166.25, 167.5, 208.0)',
'line': {'width': 0},
'opacity': 1,
'type': 'rect',
'x0': '2011-01-01',
'x1': '2012-06-05',
'xref': 'x',
'y0': 0.5,
'y1': 1.5,
'yref': 'y'}],
'showlegend': False,
'title': 'Title',
'width': 500,
'xaxis': {'rangeselector': {'buttons': [
{'count': 7,
'label': '1w',
'step': 'day',
'stepmode': 'backward'},
{'count': 1,
'label': '1m',
'step': 'month',
'stepmode': 'backward'},
{'count': 6,
'label': '6m',
'step': 'month',
'stepmode': 'backward'},
{'count': 1,
'label': 'YTD',
'step': 'year',
'stepmode': 'todate'},
{'count': 1,
'label': '1y',
'step': 'year',
'stepmode': 'backward'},
{'step': 'all'}
]},
'showgrid': True,
'type': 'date',
'zeroline': False},
'yaxis': {'autorange': False,
'range': [-1, 3],
'showgrid': True,
'ticktext': ['Run', 'Fast'],
'tickvals': [0, 1],
'zeroline': False}}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

excellent! Love this full-test 🐅!


self.assertEqual(test_gantt_chart['data'][0],
exp_gantt_chart['data'][0])

self.assertEqual(test_gantt_chart['data'][1],
exp_gantt_chart['data'][1])

self.assertEqual(test_gantt_chart['layout'],
exp_gantt_chart['layout'])

# class TestDistplot(TestCase):

# def test_scipy_import_error(self):
Expand Down
79 changes: 79 additions & 0 deletions plotly/tests/test_optional/test_figure_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -1267,6 +1267,85 @@ def test_scatter_plot_matrix_kwargs(self):
exp_scatter_plot_matrix['layout'])


class TestGantt(NumpyTestUtilsMixin, TestCase):

def test_df_dataframe(self):

# validate dataframe has correct column names
df1 = pd.DataFrame([[2, 'Apple']], columns=['Numbers', 'Fruit'])
self.assertRaises(PlotlyError, tls.FigureFactory.create_gantt, df1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't look like you have a test that indeed inputs a dataframe. The other test in test_core seems to insert a list of dict's. Can you write a 🐅 that successfully uses a dataframe to create a gannt chart?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't look like you have a test that indeed inputs a dataframe. The other test in test_core seems to insert a list of dict's. Can you write a 🐅 that successfully uses a dataframe to create a gannt chart?

Sure. How thorough should these sets of tests be? Or are you thinking of an all_args kind of thing that works?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not thorough necessarily, just an all_args. I just want to make sure that using a dataframe will continue to work.


def test_df_dataframe_all_args(self):

# check if gantt chart matches with expected output

df = pd.DataFrame([['Job A', '2009-01-01', '2009-02-30'],
['Job B', '2009-03-05', '2009-04-15']],
columns=['Task', 'Start', 'Finish'])

test_gantt_chart = tls.FigureFactory.create_gantt(df)

exp_gantt_chart = {
'data': [{'marker': {'color': 'white'},
'name': '',
'x': ['2009-01-01', '2009-02-30'],
'y': [0, 0]}],
'layout': {'height': 600,
'hovermode': 'closest',
'shapes': [{'opacity': 1,
'y1': 0.2,
'xref': 'x',
'fillcolor': 'rgb(31.0, 119.0, 180.0)',
'yref': 'y',
'y0': -0.2,
'x0': '2009-01-01',
'x1': '2009-02-30',
'type': 'rect',
'line': {'width': 0}},
{'opacity': 1,
'y1': 1.2,
'xref': 'x',
'fillcolor': 'rgb(255.0, 127.0, 14.0)',
'yref': 'y',
'y0': 0.8,
'x0': '2009-03-05',
'x1': '2009-04-15',
'type': 'rect',
'line': {'width': 0}}],
'showlegend': False,
'title': 'Gantt Chart',
'width': 900,
'xaxis': {'rangeselector': {'buttons': [
{'count': 7, 'label': '1w',
'step': 'day', 'stepmode': 'backward'},
{'count': 1, 'label': '1m',
'step': 'month', 'stepmode': 'backward'},
{'count': 6, 'label': '6m',
'step': 'month', 'stepmode': 'backward'},
{'count': 1, 'label': 'YTD',
'step': 'year', 'stepmode': 'todate'},
{'count': 1, 'label': '1y',
'step': 'year', 'stepmode': 'backward'},
{'step': 'all'}
]},
'showgrid': False,
'type': 'date',
'zeroline': False},
'yaxis': {'autorange': False,
'range': [-1, 3],
'showgrid': False,
'ticktext': ['Job A', 'Job B'],
'tickvals': [0, 1],
'zeroline': False}}
}

self.assertEqual(test_gantt_chart['data'][0],
exp_gantt_chart['data'][0])

self.assert_dict_equal(test_gantt_chart['layout'],
exp_gantt_chart['layout'])


class TestViolin(NumpyTestUtilsMixin, TestCase):

def test_colors_validation(self):
Expand Down
Loading