Skip to content

Commit

Permalink
Isue data-8#163: Fixed build errors in stack method
Browse files Browse the repository at this point in the history
  • Loading branch information
SambhaviPD committed Oct 7, 2020
1 parent cebed2b commit 5ebcdbd
Showing 1 changed file with 4 additions and 34 deletions.
38 changes: 4 additions & 34 deletions datascience/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -1835,9 +1835,6 @@ def stack(self, key, labels=None):
>>> players = Table().with_columns('player_id', \
make_array(110234, 110235), 'wOBA', make_array(.354, .236))
>>> players.stack(key='player_id')
gives the following output,
player_id | column | value
110234 | wOBA | 0.354
110235 | wOBA | 0.236
Expand All @@ -1848,10 +1845,7 @@ def stack(self, key, labels=None):
>>> players = Table().with_columns('player_id', \
make_array(110234, 110235), 'wOBA', make_array(.354, .236))
>>> players.stack(key='wOBA')
gives the following output,
wOBA | column | value
wOBA | column | value
0.354 | player_id | 110234
0.236 | player_id | 110235
Expand All @@ -1863,9 +1857,6 @@ def stack(self, key, labels=None):
'job', make_array('a', 'b', 'c', 'd'), \
'wage', make_array(10, 20, 15, 8))
>>> jobs.stack(key='wage')
gives the following output,
wage | column | value
10 | job | a
20 | job | b
Expand All @@ -1878,9 +1869,6 @@ def stack(self, key, labels=None):
'job', make_array('a', 'b', 'c', 'd'), \
'wage', make_array(10, 20, 15, 8))
>>> jobs.stack(key='job')
gives the following output,
job | column | value
a | wage | 10
b | wage | 20
Expand All @@ -1897,9 +1885,6 @@ def stack(self, key, labels=None):
'price', make_array(90.5, 90.00, 83.00, 95.50, 82.00, 82.00), \
'projection', make_array(90.75, 82.00, 82.50, 82.50, 83.00, 82.50))
>>> table.stack(key='price')
gives the following output,
price | column | value
90.5 | days | 0
90.5 | projection | 90.75
Expand All @@ -1917,8 +1902,7 @@ def stack(self, key, labels=None):
If we specify a particular label, we then get that label related values only
>>> table.stack(key='price', labels="days")
>>> table.stack(key='price', labels="days")
price | column | value
90.5 | days | 0
90 | days | 1
Expand All @@ -1929,27 +1913,13 @@ def stack(self, key, labels=None):
Example 5:
If we give a non-existent key, we get an Attribute Error
>>> players = Table().with_columns('player_id', \
make_array(110234, 110235), 'wOBA', make_array(.354, .236))
>>> players.stack(key='abc')
gives the following output,
AttributeError: Attribute (abc) not found in row.
Example 6:
If we give a non-existent label, we get an empty table without any errors
>>> players = Table().with_columns('player_id', \
make_array(110234, 110235), 'wOBA', make_array(.354, .236))
>>> players.stack(key="wOBA", labels="abc")
gives the following output,
wOBA | column | value """
wOBA | column | value
"""

rows, labels = [], labels or self.labels
for row in self.rows:
Expand Down

0 comments on commit 5ebcdbd

Please sign in to comment.