From c653802ba9a8edbbf4e283bf9217d6ba8db372a4 Mon Sep 17 00:00:00 2001 From: David Culler Date: Sat, 31 Dec 2016 21:02:32 -0800 Subject: [PATCH 1/2] Fix plot, bar, and scatter to accept width and height kwargs --- datascience/tables.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/datascience/tables.py b/datascience/tables.py index c32ea200..fe1ede3a 100644 --- a/datascience/tables.py +++ b/datascience/tables.py @@ -1890,7 +1890,7 @@ def to_array(self): 'alpha': 0.7, } - def plot(self, column_for_xticks=None, select=None, overlay=True, **vargs): + def plot(self, column_for_xticks=None, select=None, overlay=True, width=6, height=4, **vargs): """Plot line charts for the table. Args: @@ -1952,9 +1952,9 @@ def draw(axis, label, color): else: axis.plot(x_data, self[label], color=color, **options) - self._visualize(x_label, y_labels, None, overlay, draw, _vertical_x) + self._visualize(x_label, y_labels, None, overlay, draw, _vertical_x, width=width, height=height) - def bar(self, column_for_categories=None, select=None, overlay=True, **vargs): + def bar(self, column_for_categories=None, select=None, overlay=True, width=6, height=4, **vargs): """Plot bar charts for the table. Each plot is labeled using the values in `column_for_categories` and @@ -1991,9 +1991,9 @@ def annotate(axis, ticks): tick_labels = [ticks[int(l)] if 0<=l', connectionstyle = 'arc3,rad=0', color='black')) x_label = self._as_label(column_for_x) - self._visualize(x_label, y_labels, None, overlay, draw, _vertical_x, width=5, height=5) + self._visualize(x_label, y_labels, None, overlay, draw, _vertical_x, width=width, height=height) def _visualize(self, x_label, y_labels, ticks, overlay, draw, annotate, width=6, height=4): """Generic visualization that overlays or separates the draw function. From 052b1137decb17de1aec0271981974bcabe45b0b Mon Sep 17 00:00:00 2001 From: Adnan Hemani Date: Thu, 12 Jan 2017 22:07:05 -0600 Subject: [PATCH 2/2] added table.remove --- README.md | 3 +++ datascience/tables.py | 12 ++++++++++++ tests/test_tables.py | 17 +++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/README.md b/README.md index 5e0f0c1b..d56ff398 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,9 @@ pip install datascience This project adheres to [Semantic Versioning](http://semver.org/). +### v0.9.0 +- Added "Table.remove" + ### v0.8.2 - Added `proportions_from_distribution` method to `datascience.util`. diff --git a/datascience/tables.py b/datascience/tables.py index c32ea200..ed4f2291 100644 --- a/datascience/tables.py +++ b/datascience/tables.py @@ -550,6 +550,18 @@ def relabel(self, column_label, new_label): self._formats[old_to_new[label]] = formatter return self + def remove(self, row_or_row_indices): + """Removes a row or multiple rows of a table in place.""" + if not row_or_row_indices: + return + if isinstance(row_or_row_indices, int): + rows_remove = [row_or_row_indices] + else: + rows_remove = row_or_row_indices + for col in self._columns: + self._columns[col] = [elem for i, elem in enumerate(self[col]) if i not in rows_remove] + return self + ################## # Transformation # diff --git a/tests/test_tables.py b/tests/test_tables.py index c91d7a7b..c68cbfb5 100644 --- a/tests/test_tables.py +++ b/tests/test_tables.py @@ -728,6 +728,23 @@ def test_bin(table): 13 | 0 """) +def test_remove_multiple(table): + table.remove([1, 3]) + assert_equal(table, """ + letter | count | points + a | 9 | 1 + c | 3 | 2 + """) + +def test_remove_single(table): + table.remove(1) + assert_equal(table, """ + letter | count | points + a | 9 | 1 + c | 3 | 2 + z | 1 | 10 + """) + ########## # Create #