Skip to content

Commit

Permalink
test: Fix agate.Table API call
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Oct 4, 2023
1 parent fbd1a31 commit e1f3217
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 89 deletions.
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
The following individuals have contributed code to agate-stats:

* `Christopher Groskopf <https://github.com/onyxfish/>`_
* `James McKinney <https://github.com/jpmckinney>`_
10 changes: 5 additions & 5 deletions agatecharts/tableset.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def bar_chart(self, label_column_name, value_column_names, filename=None, size=N
"""
chart = Bars(label_column_name, value_column_names)

_plot(self, chart, filename, size, dpi)
plot(self, chart, filename, size, dpi)


def column_chart(self, label_column_name, value_column_names, filename=None, size=None, dpi=DEFAULT_DPI):
Expand All @@ -26,7 +26,7 @@ def column_chart(self, label_column_name, value_column_names, filename=None, siz
"""
chart = Columns(label_column_name, value_column_names)

_plot(self, chart, filename, size, dpi)
plot(self, chart, filename, size, dpi)


def line_chart(self, x_column_name, y_column_names, filename=None, size=None, dpi=DEFAULT_DPI):
Expand All @@ -35,7 +35,7 @@ def line_chart(self, x_column_name, y_column_names, filename=None, size=None, dp
"""
chart = Lines(x_column_name, y_column_names)

_plot(self, chart, filename, size, dpi)
plot(self, chart, filename, size, dpi)


def scatter_chart(self, x_column_name, y_column_name, filename=None, size=None, dpi=DEFAULT_DPI):
Expand All @@ -44,10 +44,10 @@ def scatter_chart(self, x_column_name, y_column_name, filename=None, size=None,
"""
chart = Scatter(x_column_name, y_column_name)

_plot(self, chart, filename, size, dpi)
plot(self, chart, filename, size, dpi)


def _plot(tableset, chart, filename=None, size=None, dpi=DEFAULT_DPI):
def plot(tableset, chart, filename=None, size=None, dpi=DEFAULT_DPI):
"""
See :meth:`agatecharts.table.plot`.
"""
Expand Down
21 changes: 9 additions & 12 deletions docs/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@
Tutorial
========

About agate-charts
==================

agate-charts is an extension for the `agate <http://agate.readthedocs.org/>`_ data analysis library that adds support for quickly exploring data using charts. It does not create polished or publication-ready graphics. If you haven't used agate before, please read the `agate tutorial <http://agate.readthedocs.org/>`_ before reading this.

In this tutorial we will use agate-charts to explore a `time-series dataset from the EPA <http://ampd.epa.gov/ampd/>`_ documenting US greenhouse gas emissions for the month of June 2015.

Getting setup
=============
Setup
=====

Let's start by creating a clean workspace:

Expand All @@ -25,7 +22,7 @@ Now let's download the data:
curl -L -O https://raw.githubusercontent.com/wireservice/agate-charts/master/examples/epa-emissions-20150910.csv
Install agate-charts:
And install agate-charts:

.. code-block:: bash
Expand All @@ -37,8 +34,8 @@ You will now have a file named ``epa-emissions-20150910.csv`` in your ``agate_ch

agate-charts plays nicely with `ipython <http://ipython.org/>`_, `Jupyter notebooks <https://jupyter.org/>`_ and derivative projects like Atom's `hydrogen plugin <https://atom.io/packages/hydrogen>`_. If you prefer to go through this tutorial in any of those environments all the examples will work the same. You may need to add :code:`%matplotlib inline` to the top of your scripts `as you would in an ipython notebook <https://ipython.org/ipython-doc/3/notebook/notebook.html#plotting>`_.

Importing out dependencies
==========================
Import dependencies
===================

Our only dependencies for this tutorial will be agate and agate-charts. Importing :code:`agatecharts` attaches the :mod:`agatecharts.table` methods to :class:`.Table` and the :mod:`agatecharts.tableset` methods to :class:`.TableSet`.

Expand All @@ -47,8 +44,8 @@ Our only dependencies for this tutorial will be agate and agate-charts. Importin
import agate
import agatecharts
Loading the data
================
Load data
=========

Now let's load the dataset into an :class:`.Table`. We'll use an :class:`.TypeTester` so that we don't have to specify every column, but we'll force the :code:` Date` column to be a date since it is in a known format.

Expand Down Expand Up @@ -111,8 +108,8 @@ You can also choose to render the image directly to disk, by passing the :code:`

agate-charts uses `matplotlib <http://matplotlib.org/>`_ to render charts. Matplotlib is a notoriously complicated and finicky piece of software. agate-charts attempts to abstract away all the messiest bits, but you may still have issues with charts not rendering on your particular platform. If the script hangs, or you don't see any output, try `specifying a rendering backend <http://matplotlib.org/faq/usage_faq.html#what-is-a-backend>`_ *before* importing agate-charts. This shouldn't be an issue if you're rendering to files.

Rendering multiple series
=========================
Render multiple series
======================

You may also want to render charts that compare to series of data. For instance, in this dataset the sulfur dioxide (:code:`so2`) and nitrogen oxide (:code:`nox`) amounts are on similar scales. Let's roll the data up by state and compare them with a bar chart:

Expand Down
53 changes: 35 additions & 18 deletions tests/test_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,40 @@ def setUp(self):
text_type = agate.Text()
number_type = agate.Number()

columns = (
('gender', text_type),
('month', number_type),
('median', number_type),
('stdev', number_type),
('1st', number_type),
('3rd', number_type),
('5th', number_type),
('15th', number_type),
('25th', number_type),
('50th', number_type),
('75th', number_type),
('85th', number_type),
('95th', number_type),
('97th', number_type),
('99th', number_type)
)
column_names = [
'gender',
'month',
'median',
'stdev',
'1st',
'3rd',
'5th',
'15th',
'25th',
'50th',
'75th',
'85th',
'95th',
'97th',
'99th',
]
column_types = [
text_type,
number_type,
number_type,
number_type,
number_type,
number_type,
number_type,
number_type,
number_type,
number_type,
number_type,
number_type,
number_type,
number_type,
number_type,
]

with open('examples/heights.csv') as f:
# Create a csv reader
Expand All @@ -40,7 +57,7 @@ def setUp(self):
next(f)

# Create the table
self.table = agate.Table(reader, columns)
self.table = agate.Table(reader, column_names, column_types)

if os.path.exists(TEST_FILENAME):
os.remove(TEST_FILENAME)
Expand Down
53 changes: 35 additions & 18 deletions tests/test_column.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,40 @@ def setUp(self):
text_type = agate.Text()
number_type = agate.Number()

columns = (
('gender', text_type),
('month', number_type),
('median', number_type),
('stdev', number_type),
('1st', number_type),
('3rd', number_type),
('5th', number_type),
('15th', number_type),
('25th', number_type),
('50th', number_type),
('75th', number_type),
('85th', number_type),
('95th', number_type),
('97th', number_type),
('99th', number_type)
)
column_names = [
'gender',
'month',
'median',
'stdev',
'1st',
'3rd',
'5th',
'15th',
'25th',
'50th',
'75th',
'85th',
'95th',
'97th',
'99th',
]
column_types = [
text_type,
number_type,
number_type,
number_type,
number_type,
number_type,
number_type,
number_type,
number_type,
number_type,
number_type,
number_type,
number_type,
number_type,
number_type,
]

with open('examples/heights.csv') as f:
# Create a csv reader
Expand All @@ -40,7 +57,7 @@ def setUp(self):
next(f)

# Create the table
self.table = agate.Table(reader, columns)
self.table = agate.Table(reader, column_names, column_types)

if os.path.exists(TEST_FILENAME):
os.remove(TEST_FILENAME)
Expand Down
53 changes: 35 additions & 18 deletions tests/test_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,40 @@ def setUp(self):
text_type = agate.Text()
number_type = agate.Number()

columns = (
('gender', text_type),
('month', number_type),
('median', number_type),
('stdev', number_type),
('1st', number_type),
('3rd', number_type),
('5th', number_type),
('15th', number_type),
('25th', number_type),
('50th', number_type),
('75th', number_type),
('85th', number_type),
('95th', number_type),
('97th', number_type),
('99th', number_type)
)
column_names = [
'gender',
'month',
'median',
'stdev',
'1st',
'3rd',
'5th',
'15th',
'25th',
'50th',
'75th',
'85th',
'95th',
'97th',
'99th',
]
column_types = [
text_type,
number_type,
number_type,
number_type,
number_type,
number_type,
number_type,
number_type,
number_type,
number_type,
number_type,
number_type,
number_type,
number_type,
number_type,
]

with open('examples/heights.csv') as f:
# Create a csv reader
Expand All @@ -40,7 +57,7 @@ def setUp(self):
next(f)

# Create the table
self.table = agate.Table(reader, columns)
self.table = agate.Table(reader, column_names, column_types)

if os.path.exists(TEST_FILENAME):
os.remove(TEST_FILENAME)
Expand Down
53 changes: 35 additions & 18 deletions tests/test_scatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,40 @@ def setUp(self):
text_type = agate.Text()
number_type = agate.Number()

columns = (
('gender', text_type),
('month', number_type),
('median', number_type),
('stdev', number_type),
('1st', number_type),
('3rd', number_type),
('5th', number_type),
('15th', number_type),
('25th', number_type),
('50th', number_type),
('75th', number_type),
('85th', number_type),
('95th', number_type),
('97th', number_type),
('99th', number_type)
)
column_names = [
'gender',
'month',
'median',
'stdev',
'1st',
'3rd',
'5th',
'15th',
'25th',
'50th',
'75th',
'85th',
'95th',
'97th',
'99th',
]
column_types = [
text_type,
number_type,
number_type,
number_type,
number_type,
number_type,
number_type,
number_type,
number_type,
number_type,
number_type,
number_type,
number_type,
number_type,
number_type,
]

with open('examples/heights.csv') as f:
# Create a csv reader
Expand All @@ -40,7 +57,7 @@ def setUp(self):
next(f)

# Create the table
self.table = agate.Table(reader, columns)
self.table = agate.Table(reader, column_names, column_types)

if os.path.exists(TEST_FILENAME):
os.remove(TEST_FILENAME)
Expand Down

0 comments on commit e1f3217

Please sign in to comment.