Skip to content

Commit

Permalink
Merge 4cfae7b into 2ba25c5
Browse files Browse the repository at this point in the history
  • Loading branch information
adnanhemani committed Jul 1, 2019
2 parents 2ba25c5 + 4cfae7b commit 6bc23e1
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -26,6 +26,10 @@ pip install datascience

This project adheres to [Semantic Versioning](http://semver.org/).

### v0.12.1
* Adds an `shallow` argument to `Table#select` to allow for shallow
copying of the table's data.

### v0.12.0
* Changes `Table#scatter`'s argument name of `colors` to `group` to mirror `Table#hist`.
* Makes a grouped scatterplot's legend identical to a group histogram's legend.
Expand Down
9 changes: 7 additions & 2 deletions datascience/tables.py
Expand Up @@ -596,12 +596,14 @@ def copy(self, *, shallow=False):
self._add_column_and_format(table, label, column)
return table

def select(self, *column_or_columns):
def select(self, *column_or_columns, shallow=False):
"""Return a table with only the columns in ``column_or_columns``.
Args:
``column_or_columns``: Columns to select from the ``Table`` as
either column labels (``str``) or column indices (``int``).
''shallow'': Setting this to True will select columns without
making a copy of the column.
Returns:
A new instance of ``Table`` containing only selected columns.
Expand Down Expand Up @@ -644,7 +646,10 @@ def select(self, *column_or_columns):
labels = self._varargs_as_labels(column_or_columns)
table = type(self)()
for label in labels:
self._add_column_and_format(table, label, np.copy(self[label]))
if shallow:
self._add_column_and_format(table, label, self[label])
else:
self._add_column_and_format(table, label, np.copy(self[label]))
return table

# These, along with a snippet below, are necessary for Sphinx to
Expand Down
2 changes: 1 addition & 1 deletion datascience/version.py
@@ -1 +1 @@
__version__ = '0.12.0'
__version__ = '0.12.1'
34 changes: 34 additions & 0 deletions tests/test_tables.py
Expand Up @@ -155,6 +155,40 @@ def test_select(table):
10 | 1
""")

def test_select_with_copy_values(table):
t = table.copy()
test = t.select(["points"], shallow=True)
test1 = t.select(["points"], shallow=False) #default setting
assert_equal(test, """
points
1
2
2
10
""")
t["points"][0] = 999
assert_equal(t.select("points"), """
points
999
2
2
10
""")
assert_equal(test, """
points
999
2
2
10
""")
assert_equal(test1, """
points
1
2
2
10
""")

def test_drop(table):
t = table
test = t.drop(['points', 1])
Expand Down

0 comments on commit 6bc23e1

Please sign in to comment.