Skip to content
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

Adds exception for Table.with_columns(...) #402

Merged
merged 2 commits into from
Jul 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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