Skip to content

Commit

Permalink
Merge in formatting changes from master
Browse files Browse the repository at this point in the history
  • Loading branch information
devstein committed Apr 29, 2022
2 parents bcff00b + c4b9b99 commit 7b71500
Show file tree
Hide file tree
Showing 98 changed files with 5,396 additions and 2,510 deletions.
4 changes: 4 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# .git-blame-ignore-revs
# Re-formatted entire code base with black
7ebf0753485c931db4135953dcd0864b4d089ed5

1 change: 1 addition & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

### Checklist
- [ ] Wrote a description of my changes above
- [ ] Formatted my code with [`black`](https://black.readthedocs.io/en/stable/index.html)
- [ ] Added a bullet point for my changes to the top of the `CHANGELOG.md` file
- [ ] Added or modified unit tests to reflect my changes
- [ ] Manually tested with a notebook
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Lint

on: [push, pull_request]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: psf/black@stable
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
### Updates

* Officially drop support for Python 3.6. Sparkmagic will not guarantee Python 3.6 compatibility moving forward.
* Re-format all code with [`black`](https://black.readthedocs.io/en/stable/index.html) and validate via CI


### Bug Fixes

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[![Build Status](https://travis-ci.org/jupyter-incubator/sparkmagic.svg?branch=master)](https://travis-ci.org/jupyter-incubator/sparkmagic) [![Join the chat at https://gitter.im/sparkmagic/Lobby](https://badges.gitter.im/sparkmagic/Lobby.svg)](https://gitter.im/sparkmagic/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Build Status](https://travis-ci.org/jupyter-incubator/sparkmagic.svg?branch=master)](https://travis-ci.org/jupyter-incubator/sparkmagic) [![Join the chat at https://gitter.im/sparkmagic/Lobby](https://badges.gitter.im/sparkmagic/Lobby.svg)](https://gitter.im/sparkmagic/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)


# sparkmagic

Expand Down
1 change: 0 additions & 1 deletion autovizwidget/autovizwidget/plotlygraphs/bargraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ class BarGraph(GraphBase):
def _get_data(self, df, encoding):
x_values, y_values = GraphBase._get_x_y_values(df, encoding)
return [Bar(x=x_values, y=y_values)]

18 changes: 14 additions & 4 deletions autovizwidget/autovizwidget/plotlygraphs/datagraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
class DataGraph(object):
"""This does not use the table version of plotly because it freezes up the browser for >60 rows. Instead, we use
pandas df HTML representation."""

def __init__(self, display=None):
if display is None:
self.display = IpythonDisplay()
Expand All @@ -21,7 +22,8 @@ def render(self, df, encoding, output):
show_dimensions = pd.get_option("display.show_dimensions")

# This will hide the index column for pandas df.
self.display.html("""
self.display.html(
"""
<style>
table.dataframe.hideme thead th:first-child {
display: none;
Expand All @@ -30,9 +32,17 @@ def render(self, df, encoding, output):
display: none;
}
</style>
""")
self.display.html(df.to_html(max_rows=max_rows, max_cols=max_cols,
show_dimensions=show_dimensions, notebook=True, classes="hideme"))
"""
)
self.display.html(
df.to_html(
max_rows=max_rows,
max_cols=max_cols,
show_dimensions=show_dimensions,
notebook=True,
classes="hideme",
)
)

@staticmethod
def display_logarithmic_x_axis():
Expand Down
53 changes: 35 additions & 18 deletions autovizwidget/autovizwidget/plotlygraphs/graphbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from plotly.graph_objs import Figure, Layout
from plotly.offline import iplot

try:
from pandas.core.base import DataError
except:
Expand All @@ -29,16 +30,20 @@ def render(self, df, encoding, output):
type_x_axis = self._get_type_axis(encoding.logarithmic_x_axis)
type_y_axis = self._get_type_axis(encoding.logarithmic_y_axis)

layout = Layout(xaxis=dict(type=type_x_axis, rangemode="tozero", title=encoding.x),
yaxis=dict(type=type_y_axis, rangemode="tozero", title=encoding.y))
layout = Layout(
xaxis=dict(type=type_x_axis, rangemode="tozero", title=encoding.x),
yaxis=dict(type=type_y_axis, rangemode="tozero", title=encoding.y),
)

with output:
try:
fig = Figure(data=data, layout=layout)
iplot(fig, show_link=False)
except TypeError:
print("\n\n\nPlease select another set of X and Y axis, because the type of the current axis do\n"
"not support aggregation over it.")
print(
"\n\n\nPlease select another set of X and Y axis, because the type of the current axis do\n"
"not support aggregation over it."
)

@staticmethod
def display_x():
Expand Down Expand Up @@ -68,10 +73,9 @@ def _get_data(self, df, encoding):
@staticmethod
def _get_x_y_values(df, encoding):
try:
x_values, y_values = GraphBase._get_x_y_values_aggregated(df,
encoding.x,
encoding.y,
encoding.y_aggregation)
x_values, y_values = GraphBase._get_x_y_values_aggregated(
df, encoding.x, encoding.y, encoding.y_aggregation
)
except ValueError:
x_values = GraphBase._get_x_values(df, encoding)
y_values = GraphBase._get_y_values(df, encoding)
Expand Down Expand Up @@ -99,8 +103,11 @@ def _get_x_y_values_aggregated(df, x_column, y_column, y_aggregation):
try:
df_grouped = df.groupby(x_column)
except TypeError:
raise InvalidEncodingError("Cannot group by X column '{}' because of its type: '{}'."
.format(df[x_column].dtype))
raise InvalidEncodingError(
"Cannot group by X column '{}' because of its type: '{}'.".format(
df[x_column].dtype
)
)
else:
try:
if y_aggregation == Encoding.y_agg_avg:
Expand All @@ -114,20 +121,30 @@ def _get_x_y_values_aggregated(df, x_column, y_column, y_aggregation):
elif y_aggregation == Encoding.y_agg_count:
df_transformed = df_grouped.count()
else:
raise ValueError("Y aggregation '{}' not supported.".format(y_aggregation))
raise ValueError(
"Y aggregation '{}' not supported.".format(y_aggregation)
)
except (DataError, ValueError) as err:
raise InvalidEncodingError("Cannot aggregate column '{}' with aggregation function '{}' because:\n\t'{}'."
.format(y_column, y_aggregation, err))
raise InvalidEncodingError(
"Cannot aggregate column '{}' with aggregation function '{}' because:\n\t'{}'.".format(
y_column, y_aggregation, err
)
)
except TypeError:
raise InvalidEncodingError("Cannot aggregate column '{}' with aggregation function '{}' because the type\n"
"cannot be aggregated over."
.format(y_column, y_aggregation))
raise InvalidEncodingError(
"Cannot aggregate column '{}' with aggregation function '{}' because the type\n"
"cannot be aggregated over.".format(y_column, y_aggregation)
)
else:
df_transformed = df_transformed.reset_index()

if y_column not in df_transformed.columns:
raise InvalidEncodingError("Y column '{}' is not valid with aggregation function '{}'. Please select "
"a different\naggregation function.".format(y_column, y_aggregation))
raise InvalidEncodingError(
"Y column '{}' is not valid with aggregation function '{}'. Please select "
"a different\naggregation function.".format(
y_column, y_aggregation
)
)

x_values = df_transformed[x_column].tolist()
y_values = df_transformed[y_column].tolist()
Expand Down
1 change: 0 additions & 1 deletion autovizwidget/autovizwidget/plotlygraphs/graphrenderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@


class GraphRenderer(object):

@staticmethod
def render(df, encoding, output):
with output:
Expand Down
1 change: 0 additions & 1 deletion autovizwidget/autovizwidget/plotlygraphs/linegraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


class LineGraph(GraphBase):

def _get_data(self, df, encoding):
x_values, y_values = GraphBase._get_x_y_values(df, encoding)
return [Scatter(x=x_values, y=y_values)]
26 changes: 18 additions & 8 deletions autovizwidget/autovizwidget/plotlygraphs/piegraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@

from plotly.graph_objs import Pie, Figure
from plotly.offline import iplot

try:
from pandas.core.base import DataError
except:
from pandas.core.groupby import DataError

import autovizwidget.utils.configuration as conf
from .graphbase import GraphBase

Expand All @@ -24,13 +25,19 @@ def render(df, encoding, output):
values, labels = PieGraph._get_x_values_labels(df, encoding)
except TypeError:
with output:
print("\n\n\nCannot group by X selection because of its type: '{}'. Please select another column."
.format(df[encoding.x].dtype))
print(
"\n\n\nCannot group by X selection because of its type: '{}'. Please select another column.".format(
df[encoding.x].dtype
)
)
return
except (ValueError, DataError):
with output:
print("\n\n\nCannot group by X selection. Please select another column."
.format(df[encoding.x].dtype))
print(
"\n\n\nCannot group by X selection. Please select another column.".format(
df[encoding.x].dtype
)
)
if df.size == 0:
print("\n\n\nCannot display a pie graph for an empty data set.")
return
Expand All @@ -42,9 +49,12 @@ def render(df, encoding, output):
# 500 rows take ~15 s.
# 100 rows is almost automatic.
if len(values) > max_slices_pie_graph:
print("There's {} values in your pie graph, which would render the graph unresponsive.\n"
"Please select another X with at most {} possible values."
.format(len(values), max_slices_pie_graph))
print(
"There's {} values in your pie graph, which would render the graph unresponsive.\n"
"Please select another X with at most {} possible values.".format(
len(values), max_slices_pie_graph
)
)
else:
data = [Pie(values=values, labels=labels)]

Expand Down
3 changes: 1 addition & 2 deletions autovizwidget/autovizwidget/plotlygraphs/scattergraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class ScatterGraph(GraphBase):

def _get_data(self, df, encoding):
x_values, y_values = GraphBase._get_x_y_values(df, encoding)
return [Scatter(x=x_values, y=y_values, mode='markers')]
return [Scatter(x=x_values, y=y_values, mode="markers")]

0 comments on commit 7b71500

Please sign in to comment.