Skip to content

Commit

Permalink
Merge branch 'master' into shaded_histograms
Browse files Browse the repository at this point in the history
  • Loading branch information
davidwagner committed Jul 23, 2019
2 parents a21df65 + 4e6a0e9 commit 5e512d1
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
* Added support for shading part of a histogram, e.g., for highlighting
the tail of a distribution.

### v0.14.1
* Adds optional argument to `Table#from_df` that keeps the index when
converting from a Pandas dataframe.

### v0.14.0
* Declares all dependencies required for this package in requirements.txt.

Expand Down
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,3 @@ pip install datascience
```

A log of all changes can be found in CHANGELOG.md.

Information for developing or modifying this package can be
found in DEVELOPERS.md.
8 changes: 4 additions & 4 deletions datascience/maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,9 @@ class Marker(_MapFeature):
popup -- text that pops up when marker is clicked
color -- The color of the marker. You can use:
[‘red’, ‘blue’, ‘green’, ‘purple’, ‘orange’, ‘darkred’,
’lightred’, ‘beige’, ‘darkblue’, ‘darkgreen’, ‘cadetblue’, ‘darkpurple’,
‘white’, ‘pink’, ‘lightblue’, ‘lightgreen’, ‘gray’, ‘black’, ‘lightgray’]
[‘red’, ‘blue’, ‘green’, ‘purple’, ‘orange’, ‘darkred’,
’lightred’, ‘beige’, ‘darkblue’, ‘darkgreen’, ‘cadetblue’, ‘darkpurple’,
‘white’, ‘pink’, ‘lightblue’, ‘lightgreen’, ‘gray’, ‘black’, ‘lightgray’]
Defaults from Folium:
Expand All @@ -429,7 +429,6 @@ class Marker(_MapFeature):
"""

def __init__(self, lat, lon, popup='', color='blue', **kwargs):
#TODO: Figure out clustered_marker (Adnan)
assert isinstance(lat, _number)
assert isinstance(lon, _number)
self.lat_lon = (lat, lon)
Expand Down Expand Up @@ -494,6 +493,7 @@ def map(cls, latitudes, longitudes, labels=None, colors=None, areas=None, cluste
The areas column is not applicable to markers, but sets circle areas.
Arguments: (TODO) document all options
clustered_marker: boolean, default False
boolean of whether or not you want the marker clustered with other markers
Expand Down
12 changes: 10 additions & 2 deletions datascience/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,17 @@ def _add_column_and_format(self, table, label, column):
table._formats[label] = self._formats[label]

@classmethod
def from_df(cls, df):
"""Convert a Pandas DataFrame into a Table."""
def from_df(cls, df, keep_index=False):
"""Convert a Pandas DataFrame into a Table.
`keep_index` -- keeps the index of the DataFrame
and turns it into a column called `index` in
the new Table
"""
t = cls()
if keep_index:
t.append_column("index", df.index.values)
labels = df.columns
for label in labels:
t.append_column(label, df[label])
Expand Down
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
tests_requires = [
'pytest',
'coverage==4.5.3',
'coveralls'
'coveralls',
'bokeh'
]


Expand Down Expand Up @@ -47,6 +48,7 @@ def run_tests(self):
tests_require = tests_requires,
cmdclass = {'test': PyTest},
description = 'A Jupyter notebook Python library for introductory data science',
long_description = 'A Jupyter notebook Python library for introductory data science',
author = 'John DeNero, David Culler, Alvin Wan, Sam Lau',
author_email = 'ds8-instructors@berkeley.edu',
url = 'https://github.com/data-8/datascience',
Expand Down
9 changes: 9 additions & 0 deletions tests/test_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -1720,6 +1720,15 @@ def test_df_roundtrip(table):
for (c0, c1) in zip(t.columns, table.columns):
assert_equal(c0, c1)

def test_from_df_with_index(table):
from bokeh.sampledata.autompg import autompg as df
assert isinstance(df, pd.DataFrame)
test_no_index = Table.from_df(df)
assert not ("index" in test_no_index.labels)
test_with_index = Table.from_df(df, keep_index=True)
assert "index" in test_with_index.labels
assert test_with_index.num_columns == (test_no_index.num_columns + 1)

def test_array_roundtrip(table):
arr = table.to_array()
assert isinstance(arr, np.ndarray)
Expand Down

0 comments on commit 5e512d1

Please sign in to comment.