Skip to content

Commit

Permalink
Merge pull request #402 from data-8/warn_with_columns
Browse files Browse the repository at this point in the history
Adds exception for Table.with_columns(...)
  • Loading branch information
davidwagner committed Jul 15, 2019
2 parents e585ca2 + 8088883 commit 24b53e9
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.

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

### v0.13.6
* Adds a warning to help students realize why `Table.with_columns(...)` doesn't work.

### v0.13.5
* Adds support for other built-in tile sets other than `OpenStreetMap` to `Map`.

Expand Down
3 changes: 3 additions & 0 deletions datascience/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -1734,6 +1734,9 @@ def with_columns(self, *labels_and_values, **formatter):
...
ValueError: Column length mismatch. New column does not have the same number of rows as table.
"""
if not isinstance(self, Table):
raise TypeError('Use Table().with_columns() to create a new table, \
not Table.with_columns()')
if len(labels_and_values) == 1:
labels_and_values = labels_and_values[0]
if isinstance(labels_and_values, collections.abc.Mapping):
Expand Down
2 changes: 1 addition & 1 deletion datascience/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.13.5'
__version__ = '0.13.6'
4 changes: 4 additions & 0 deletions tests/test_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,10 @@ def test_with_columns():
110235 | 0.236 | $15,500,000 | 2016 | 1
""")

def test_with_columns_exception_for_incorrect_usage():
with(pytest.raises(TypeError)):
Table.with_columns('player_id', make_array(110234, 110235), 'wOBA', make_array(.354, .236))

def test_with_columns_with_formats():
players = Table().with_columns('player_id', make_array(110234, 110235), 'wOBA', make_array(.354, .236))
assert_equal(players, """
Expand Down

0 comments on commit 24b53e9

Please sign in to comment.