Skip to content

Commit

Permalink
changed default formatting back to without commas
Browse files Browse the repository at this point in the history
  • Loading branch information
adnanhemani committed Jul 3, 2019
1 parent 4967a1b commit 5e33488
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 39 deletions.
2 changes: 1 addition & 1 deletion datascience/formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def format_value(value):
if isinstance(value, (bool, np.bool_)):
return str(value)
elif isinstance(value, (int, np.integer)):
return '{:,d}'.format(value)
return '{:d}'.format(value)
elif isinstance(value, (float, np.floating)):
return '{:g}'.format(value)
else:
Expand Down
26 changes: 13 additions & 13 deletions datascience/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,15 +524,15 @@ def relabel(self, column_label, new_label):
... 'id', make_array(12345, 123, 5123))
>>> table.relabel('id', 'yolo')
points | yolo
1 | 12,345
1 | 12345
2 | 123
3 | 5,123
3 | 5123
>>> table.relabel(make_array('points', 'yolo'),
... make_array('red', 'blue'))
red | blue
1 | 12,345
1 | 12345
2 | 123
3 | 5,123
3 | 5123
>>> table.relabel(make_array('red', 'green', 'blue'),
... make_array('cyan', 'magenta', 'yellow', 'key'))
Traceback (most recent call last):
Expand Down Expand Up @@ -1710,21 +1710,21 @@ def with_columns(self, *labels_and_values, **formatter):
>>> players = Table().with_columns('player_id',
... make_array(110234, 110235), 'wOBA', make_array(.354, .236))
>>> players
player_id | wOBA
110,234 | 0.354
110,235 | 0.236
player_id | wOBA
110234 | 0.354
110235 | 0.236
>>> players = players.with_columns('salaries', 'N/A', 'season', 2016)
>>> players
player_id | wOBA | salaries | season
110,234 | 0.354 | N/A | 2,016
110,235 | 0.236 | N/A | 2,016
player_id | wOBA | salaries | season
110234 | 0.354 | N/A | 2016
110235 | 0.236 | N/A | 2016
>>> salaries = Table().with_column('salary',
... make_array(500000, 15500000))
>>> players.with_columns('salaries', salaries.column('salary'),
... 'bonus', make_array(6, 1), formatter=_formats.CurrencyFormatter)
player_id | wOBA | salaries | season | bonus
110,234 | 0.354 | $500,000 | 2,016 | $6
110,235 | 0.236 | $15,500,000 | 2,016 | $1
player_id | wOBA | salaries | season | bonus
110234 | 0.354 | $500,000 | 2016 | $6
110235 | 0.236 | $15,500,000 | 2016 | $1
>>> players.with_columns(2, make_array('$600,000', '$20,000,000'))
Traceback (most recent call last):
...
Expand Down
4 changes: 2 additions & 2 deletions tests/test_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def test_doctests():
def test_default_format():
fmt = ds.default_formatter.format_value
assert_equal(fmt(1.23456789), '1.23457')
assert_equal(fmt(123456789), '123,456,789')
assert_equal(fmt(123456789**5), '28,679,718,602,997,181,072,337,614,380,936,720,482,949')
assert_equal(fmt(123456789), '123456789')
assert_equal(fmt(123456789**5), '28679718602997181072337614380936720482949')
assert_equal(fmt(123.456789**5), '2.86797e+10')
assert_equal(fmt(True), 'True')
assert_equal(fmt(False), 'False')
Expand Down
46 changes: 23 additions & 23 deletions tests/test_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -823,43 +823,43 @@ def test_with_column_with_formatter(table):
def test_with_columns():
players = Table().with_columns('player_id', make_array(110234, 110235), 'wOBA', make_array(.354, .236))
assert_equal(players, """
player_id | wOBA
110,234 | 0.354
110,235 | 0.236
player_id | wOBA
110234 | 0.354
110235 | 0.236
""")
players = players.with_columns('salaries', 'N/A', 'season', 2016)
assert_equal(players, """
player_id | wOBA | salaries | season
110,234 | 0.354 | N/A | 2,016
110,235 | 0.236 | N/A | 2,016
player_id | wOBA | salaries | season
110234 | 0.354 | N/A | 2016
110235 | 0.236 | N/A | 2016
""")
salaries = Table().with_column('salary', make_array('$500,000', '$15,500,000'))
players = players.with_columns('salaries', salaries.column('salary'), 'years', make_array(6, 1))
assert_equal(players, """
player_id | wOBA | salaries | season | years
110,234 | 0.354 | $500,000 | 2,016 | 6
110,235 | 0.236 | $15,500,000 | 2,016 | 1
player_id | wOBA | salaries | season | years
110234 | 0.354 | $500,000 | 2016 | 6
110235 | 0.236 | $15,500,000 | 2016 | 1
""")

def test_with_columns_with_formats():
players = Table().with_columns('player_id', make_array(110234, 110235), 'wOBA', make_array(.354, .236))
assert_equal(players, """
player_id | wOBA
110,234 | 0.354
110,235 | 0.236
110234 | 0.354
110235 | 0.236
""")
players = players.with_columns('salaries', 'N/A', 'season', 2016)
assert_equal(players, """
player_id | wOBA | salaries | season
110,234 | 0.354 | N/A | 2,016
110,235 | 0.236 | N/A | 2,016
player_id | wOBA | salaries | season
110234 | 0.354 | N/A | 2016
110235 | 0.236 | N/A | 2016
""")
salaries = Table().with_column('salary', make_array(500000, 15500000))
players2 = players.with_columns('salaries', salaries.column('salary'), 'years', make_array(6, 1), formatter=CurrencyFormatter)
assert_equal(players2, """
player_id | wOBA | salaries | season | years
110,234 | 0.354 | $500,000 | 2,016 | $6
110,235 | 0.236 | $15,500,000 | 2,016 | $1
player_id | wOBA | salaries | season | years
110234 | 0.354 | $500,000 | 2016 | $6
110235 | 0.236 | $15,500,000 | 2016 | $1
""")

with(pytest.raises(Exception)):
Expand Down Expand Up @@ -920,23 +920,23 @@ def test_relabel():
table.relabel('id', 'todo')
assert_equal(table, """
points | todo
1 | 12,345
1 | 12345
2 | 123
3 | 5,123
3 | 5123
""")
table.relabel(1, 'yolo')
assert_equal(table, """
points | yolo
1 | 12,345
1 | 12345
2 | 123
3 | 5,123
3 | 5123
""")
table.relabel(['points', 'yolo'], ['red', 'blue'])
assert_equal(table, """
red | blue
1 | 12,345
1 | 12345
2 | 123
3 | 5,123
3 | 5123
""")
with(pytest.raises(ValueError)):
table.relabel(['red', 'blue'], ['magenta', 'cyan', 'yellow'])
Expand Down

0 comments on commit 5e33488

Please sign in to comment.