From ac6f666d6bab9dd8fbe1ce4d243b917021049c4f Mon Sep 17 00:00:00 2001 From: Sam Maurer Date: Fri, 29 Mar 2019 14:02:49 -0700 Subject: [PATCH 1/8] Setting up ColumnFromBroadcast --- .../data/column_from_broadcast.py | 210 ++++++++++++++++++ 1 file changed, 210 insertions(+) create mode 100644 urbansim_templates/data/column_from_broadcast.py diff --git a/urbansim_templates/data/column_from_broadcast.py b/urbansim_templates/data/column_from_broadcast.py new file mode 100644 index 0000000..f0c3c7a --- /dev/null +++ b/urbansim_templates/data/column_from_broadcast.py @@ -0,0 +1,210 @@ +from __future__ import print_function + +import re + +import orca +import pandas as pd + +from urbansim_templates import modelmanager, __version__ +from urbansim_templates.utils import get_df + + +@modelmanager.template +class ColumnFromBroadcast(): + """ + Template to register a column of derived data with Orca, generated by mapping values + from another table via one or more join keys. Values will be calculated lazily, only + when the column is needed for a specific operation. + + All the parameters can also be set as properties after creating the template + instance. + + Parameters + ---------- + column_name : str, optional + Name of Orca column to be created. Required before running. + + destination_table : str, optional + Name of Orca table the column will be associated with. Required before running. + + source_table : str or list of str, optional + Name of Orca table containing the original data. Required before running. Must be + joinable to the destination table using standard ModelManager schema rules: there + should be a join key column in the destination table with the same name as the + source table's index. Joining on multi-indexes is supported. You may also provide + a source *chain* here, listing multiple tables. These will be combined using + :func:`~urbansim_templates.utils.merge_tables()` before generating the new + column. If you provide a list, the first item must be the destination table. + + source_column : str, optional + Name of column in the source table to map to the destination table. Required + before running. You may also provide an expression here, describing operations on + one or more columns from the source and destination tables. Same expression rules + as :mod:`~urbansim_templates.data.ColumnFromExpression()`. + + data_type : str, optional + Python type or ``numpy.dtype`` to cast the column's values into. + + missing_values : str or numeric, optional + Value to use for rows that would otherwise be missing. + + cache : bool, default False + Whether to cache column values after they are calculated. + + cache_scope : 'step', 'iteration', or 'forever', default 'forever' + How long to cache column values for (ignored if ``cache`` is False). + + name : str, optional + Name of the template instance and associated model step. + + tags : list of str, optional + Tags to associate with the template instance. + + autorun : bool, default True + Whether to run automatically when the template instance is registered with + ModelManager. + + """ + def __init__(self, + column_name = None, + destination_table = None, + source_table = None, + source_column = None, + data_type = None, + missing_values = None, + cache = False, + cache_scope = 'forever', + name = None, + tags = [], + autorun = True): + + # Template-specific params + self.column_name = column_name + self.destination_table = destination_table + self.source_table = source_table + self.source_column = source_column + self.data_type = data_type + self.missing_values = missing_values + self.cache = cache + self.cache_scope = cache_scope + + # Standard params + self.name = name + self.tags = tags + self.autorun = autorun + + # Automatic params + self.template = self.__class__.__name__ + self.template_version = __version__ + + + @classmethod + def from_dict(cls, d): + """ + Create an object instance from a saved dictionary representation. + + Parameters + ---------- + d : dict + + Returns + ------- + Table + + """ + obj = cls( + column_name = d['column_name'], + destination_table = d['destination_table'], + source_table = d['source_table'], + source_column = d['source_column'], + data_type = d['data_type'], + missing_values = d['missing_values'], + cache = d['cache'], + cache_scope = d['cache_scope'], + name = d['name'], + tags = d['tags'], + autorun = d['autorun'] + ) + return obj + + + def to_dict(self): + """ + Create a dictionary representation of the object. + + Returns + ------- + dict + + """ + d = { + 'template': self.template, + 'template_version': self.template_version, + 'name': self.name, + 'tags': self.tags, + 'autorun': self.autorun, + 'column_name': self.column_name, + 'destination_table': self.destination_table, + 'source_table': self.source_table, + 'source_column': self.source_column, + 'data_type': self.data_type, + 'missing_values': self.missing_values, + 'cache': self.cache, + 'cache_scope': self.cache_scope, + } + return d + + + def run(self): + """ + Run the template, registering a column of derived data with Orca. + + Requires values to be set for ``column_name``, ``destination_table``, + ``source_table``, and ``source_column``. + + Returns + ------- + None + + """ + if self.column_name is None: + raise ValueError("Please provide a column name") + + if self.destination_table is None: + raise ValueError("Please provide a destination table") + + if self.source_table is None: + raise ValueError("Please provide a source table") + + if self.source_column is None: + raise ValueError("Please provide a source column") + + + + + + # Some column names in the expression may not be part of the core DataFrame, so + # we'll need to request them from Orca explicitly. This regex pulls out column + # names into a list, by identifying tokens in the expression that begin with a + # letter and contain any number of alphanumerics or underscores, but do not end + # with an opening parenthesis. This will also pick up constants, like "pi", but + # invalid column names will be ignored when we request them from get_df(). +# cols = re.findall('[a-zA-Z_][a-zA-Z0-9_]*(?!\()', self.expression) +# +# @orca.column(table_name = self.table, +# column_name = self.column_name, +# cache = self.cache, +# cache_scope = self.cache_scope) +# def orca_column(): +# df = get_df(self.table, columns=cols) +# series = df.eval(self.expression) +# +# if self.missing_values is not None: +# series = series.fillna(self.missing_values) +# +# if self.data_type is not None: +# series = series.astype(self.data_type) +# +# return series + + \ No newline at end of file From db825b04411b6c7c989544c351009fc454c50c8b Mon Sep 17 00:00:00 2001 From: Sam Maurer Date: Fri, 29 Mar 2019 14:17:39 -0700 Subject: [PATCH 2/8] Basic implementation --- .../data/column_from_broadcast.py | 52 +++++++++---------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/urbansim_templates/data/column_from_broadcast.py b/urbansim_templates/data/column_from_broadcast.py index f0c3c7a..6f3ca71 100644 --- a/urbansim_templates/data/column_from_broadcast.py +++ b/urbansim_templates/data/column_from_broadcast.py @@ -6,7 +6,7 @@ import pandas as pd from urbansim_templates import modelmanager, __version__ -from urbansim_templates.utils import get_df +from urbansim_templates.utils import merge_tables @modelmanager.template @@ -179,32 +179,28 @@ def run(self): if self.source_column is None: raise ValueError("Please provide a source column") - - - - - # Some column names in the expression may not be part of the core DataFrame, so - # we'll need to request them from Orca explicitly. This regex pulls out column - # names into a list, by identifying tokens in the expression that begin with a - # letter and contain any number of alphanumerics or underscores, but do not end - # with an opening parenthesis. This will also pick up constants, like "pi", but - # invalid column names will be ignored when we request them from get_df(). -# cols = re.findall('[a-zA-Z_][a-zA-Z0-9_]*(?!\()', self.expression) -# -# @orca.column(table_name = self.table, -# column_name = self.column_name, -# cache = self.cache, -# cache_scope = self.cache_scope) -# def orca_column(): -# df = get_df(self.table, columns=cols) -# series = df.eval(self.expression) -# -# if self.missing_values is not None: -# series = series.fillna(self.missing_values) -# -# if self.data_type is not None: -# series = series.astype(self.data_type) -# -# return series + tables = [self.destination_table, self.source_table] + + if isinstance(self.source_table, list): + tables = self.source_table + + # TO DO: move this to a utility + cols = re.findall('[a-zA-Z_][a-zA-Z0-9_]*(?!\()', self.source_column) + + @orca.column(table_name = self.destination_table, + column_name = self.column_name, + cache = self.cache, + cache_scope = self.cache_scope) + def orca_column(): + df = merge_tables(tables, columns=cols) + series = df.eval(self.source_column) + + if self.missing_values is not None: + series = series.fillna(self.missing_values) + + if self.data_type is not None: + series = series.astype(self.data_type) + + return series \ No newline at end of file From 08cc583dfdd20a64816e3548fca3a11bc2f53480 Mon Sep 17 00:00:00 2001 From: Sam Maurer Date: Fri, 29 Mar 2019 14:35:10 -0700 Subject: [PATCH 3/8] Initial tests --- tests/test_column_broadcast.py | 193 ++++++++++++++++++ urbansim_templates/data/__init__.py | 1 + .../data/column_from_broadcast.py | 1 - .../data/column_from_expression.py | 1 - 4 files changed, 194 insertions(+), 2 deletions(-) create mode 100644 tests/test_column_broadcast.py diff --git a/tests/test_column_broadcast.py b/tests/test_column_broadcast.py new file mode 100644 index 0000000..29f04f3 --- /dev/null +++ b/tests/test_column_broadcast.py @@ -0,0 +1,193 @@ +import numpy as np +import pandas as pd +import pytest + +import orca + +from urbansim_templates import modelmanager +from urbansim_templates.data import ColumnFromBroadcast +from urbansim_templates.utils import validate_template + + +@pytest.fixture +def orca_session(): + """ + Set up a clean Orca and ModelManager session, with data tables. + + """ + orca.clear_all() + modelmanager.initialize() + + d1 = {'id': np.arange(5), + 'a': np.random.random(5), + 'b': np.random.choice(np.arange(20), size=5)} + + df = pd.DataFrame(d1).set_index('id') + orca.add_table('obs', df) + + # TO DO: add another table + + +def test_template_validity(): + """ + Check template conforms to basic spec. + + """ + assert validate_template(ColumnFromBroadcast) + + +# def test_missing_colname(orca_session): +# """ +# Missing column_name should raise a ValueError. +# +# """ +# c = ColumnFromExpression() +# c.table = 'tab' +# c.expression = 'a' +# +# try: +# c.run() +# except ValueError as e: +# print(e) +# return +# +# pytest.fail() +# +# +# def test_missing_table(orca_session): +# """ +# Missing table should raise a ValueError. +# +# """ +# c = ColumnFromExpression() +# c.column_name = 'col' +# c.expression = 'a' +# +# try: +# c.run() +# except ValueError as e: +# print(e) +# return +# +# pytest.fail() +# +# +# def test_missing_expression(orca_session): +# """ +# Missing expression should raise a ValueError. +# +# """ +# c = ColumnFromExpression() +# c.column_name = 'col' +# c.table = 'tab' +# +# try: +# c.run() +# except ValueError as e: +# print(e) +# return +# +# pytest.fail() +# +# +# def test_expression(orca_session): +# """ +# Check that column is created and expression evaluated correctly. +# +# """ +# c = ColumnFromExpression() +# c.column_name = 'c' +# c.table = 'obs' +# c.expression = 'a * 5 + sqrt(b)' +# +# c.run() +# +# val1 = orca.get_table('obs').get_column('c') +# df = orca.get_table('obs').to_frame() +# val2 = df.a * 5 + np.sqrt(df.b) +# assert(val1.equals(val2)) +# +# +# def test_data_type(orca_session): +# """ +# Check that casting data type works. +# +# """ +# orca.add_table('tab', pd.DataFrame({'a': [0.1, 1.33, 2.4]})) +# +# c = ColumnFromExpression() +# c.column_name = 'b' +# c.table = 'tab' +# c.expression = 'a' +# c.run() +# +# v1 = orca.get_table('tab').get_column('b').values +# np.testing.assert_equal(v1, [0.1, 1.33, 2.4]) +# +# c.data_type = 'int' +# c.run() +# +# v1 = orca.get_table('tab').get_column('b').values +# np.testing.assert_equal(v1, [0, 1, 2]) +# +# +# def test_missing_values(orca_session): +# """ +# Check that filling in missing values works. +# +# """ +# orca.add_table('tab', pd.DataFrame({'a': [0.1, np.nan, 2.4]})) +# +# c = ColumnFromExpression() +# c.column_name = 'b' +# c.table = 'tab' +# c.expression = 'a' +# c.run() +# +# v1 = orca.get_table('tab').get_column('b').values +# np.testing.assert_equal(v1, [0.1, np.nan, 2.4]) +# +# c.missing_values = 5 +# c.run() +# +# v1 = orca.get_table('tab').get_column('b').values +# np.testing.assert_equal(v1, [0.1, 5.0, 2.4]) +# +# +# def test_modelmanager_registration(orca_session): +# """ +# Check that modelmanager registration and auto-run work as expected. +# +# """ +# c = ColumnFromExpression() +# c.column_name = 'c' +# c.table = 'obs' +# c.expression = 'a + b' +# +# modelmanager.register(c) +# modelmanager.remove_step(c.name) +# assert('c' in orca.get_table('obs').columns) +# +# +# def test_expression_with_standalone_columns(orca_session): +# """ +# Check that expression can assemble data from stand-alone columns that are not part +# of the core DataFrame wrapped by a table. +# +# """ +# c = ColumnFromExpression() +# c.column_name = 'c' +# c.table = 'obs' +# c.expression = 'a + b' +# +# modelmanager.register(c) +# modelmanager.remove_step(c.name) +# +# d = ColumnFromExpression() +# d.column_name = 'd' +# d.table = 'obs' +# d.expression = 'a + c' +# +# d.run() +# assert('d' in orca.get_table('obs').columns) +# diff --git a/urbansim_templates/data/__init__.py b/urbansim_templates/data/__init__.py index 90dc264..52da67f 100644 --- a/urbansim_templates/data/__init__.py +++ b/urbansim_templates/data/__init__.py @@ -1,3 +1,4 @@ +from .column_from_broadcast import ColumnFromBroadcast from .column_from_expression import ColumnFromExpression from .load_table import LoadTable from .save_table import SaveTable diff --git a/urbansim_templates/data/column_from_broadcast.py b/urbansim_templates/data/column_from_broadcast.py index 6f3ca71..474036b 100644 --- a/urbansim_templates/data/column_from_broadcast.py +++ b/urbansim_templates/data/column_from_broadcast.py @@ -3,7 +3,6 @@ import re import orca -import pandas as pd from urbansim_templates import modelmanager, __version__ from urbansim_templates.utils import merge_tables diff --git a/urbansim_templates/data/column_from_expression.py b/urbansim_templates/data/column_from_expression.py index a7ce796..5a19c07 100644 --- a/urbansim_templates/data/column_from_expression.py +++ b/urbansim_templates/data/column_from_expression.py @@ -3,7 +3,6 @@ import re import orca -import pandas as pd from urbansim_templates import modelmanager, __version__ from urbansim_templates.utils import get_df From ab68574cc5a2618620a99d3a8b343200c4dc766a Mon Sep 17 00:00:00 2001 From: Sam Maurer Date: Mon, 1 Apr 2019 11:02:47 -0700 Subject: [PATCH 4/8] Documentation cleanup --- README.md | 2 +- docs/source/data-templates.rst | 4 ++-- docs/source/getting-started.rst | 4 +--- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 8ec043e..aa56c8e 100644 --- a/README.md +++ b/README.md @@ -26,4 +26,4 @@ See the online documentation for much more: https://urbansim-templates.readthedo Some additional documentation is available within the repo in `CHANGELOG.md`, `CONTRIBUTING.md`, `/docs/README.md`, and `/tests/README.md`. -There's discussion of current and planned features in the [Pull requests](https://github.com/udst/urbansim_templates/pulls?utf8=✓&q=is%3Apr) and [Issues](https://github.com/udst/urbansim_templates/issues?utf8=✓&q=is%3Aissue), both open and closed. +There's discussion of current and planned features in the open and closed [Pull requests](https://github.com/udst/urbansim_templates/pulls?utf8=✓&q=is%3Apr) and [Issues](https://github.com/udst/urbansim_templates/issues?utf8=✓&q=is%3Aissue). diff --git a/docs/source/data-templates.rst b/docs/source/data-templates.rst index 9317a3e..c952f66 100644 --- a/docs/source/data-templates.rst +++ b/docs/source/data-templates.rst @@ -16,7 +16,7 @@ Example t = LoadTable() t.table = 'buildings' # a name for the Orca table t.source_type = 'csv' - t.path = 'buildings.csv' + t.path = '../data/buildings.csv' t.csv_index_cols = 'building_id' t.name = 'load_buildings' # a name for the model step that sets up the table @@ -38,7 +38,7 @@ Registration does two things: (a) it saves the configured template to disk as a import orca orca.run(['load_buildings']) -Strictly speaking, running the model step doesn't load the data, it just sets up an Orca table with instructions for loading the data when it's needed. (This is called lazy evaluation.) +Strictly speaking, running the template/step doesn't load the data, it just sets up an Orca table with instructions for loading the data when it's needed. (This is called lazy evaluation.) .. code-block:: python diff --git a/docs/source/getting-started.rst b/docs/source/getting-started.rst index 1dce43d..8c598b0 100644 --- a/docs/source/getting-started.rst +++ b/docs/source/getting-started.rst @@ -18,9 +18,7 @@ UrbanSim Templates was created in 2018 by Sam Maurer (maurer@urbansim.com), who Installation ------------ -UrbanSim Templates is tested with Python versions 2.7, 3.5, 3.6, and 3.7. - -As of Feb. 2019, there is an installation problem in Python 3.7 when using Pip (because of an issue with Orca's PyTables dependency). Conda should work. +UrbanSim Templates is tested with Python versions 2.7, 3.5, 3.6, and 3.7, across Mac, Linux, and Windows. Support for Python 2.7 will probably be removed in an upcoming release. .. note:: It can be helpful to set up a dedicated Python environment for each project you work on. This lets you use a stable and replicable set of libraries that won't be affected by other projects. Here are some good `environment settings `__ for UrbanSim Templates projects. From 8c9b0bd1650eda7943d9b776c69a1bae5951cd8b Mon Sep 17 00:00:00 2001 From: Sam Maurer Date: Mon, 1 Apr 2019 11:13:19 -0700 Subject: [PATCH 5/8] Better filenames --- tests/pytest.ini | 1 + urbansim_templates/data/__init__.py | 8 ++++---- .../{column_from_broadcast.py => column_broadcast.py} | 0 .../{column_from_expression.py => column_expression.py} | 0 urbansim_templates/data/{load_table.py => table_load.py} | 0 urbansim_templates/data/{save_table.py => table_save.py} | 0 6 files changed, 5 insertions(+), 4 deletions(-) rename urbansim_templates/data/{column_from_broadcast.py => column_broadcast.py} (100%) rename urbansim_templates/data/{column_from_expression.py => column_expression.py} (100%) rename urbansim_templates/data/{load_table.py => table_load.py} (100%) rename urbansim_templates/data/{save_table.py => table_save.py} (100%) diff --git a/tests/pytest.ini b/tests/pytest.ini index 5574886..b34a956 100644 --- a/tests/pytest.ini +++ b/tests/pytest.ini @@ -5,5 +5,6 @@ filterwarnings = ignore:::pandas ignore:::past ignore:::prettytable + ignore:::scipy ignore:::statsmodels ignore:::yaml \ No newline at end of file diff --git a/urbansim_templates/data/__init__.py b/urbansim_templates/data/__init__.py index 52da67f..54c9a99 100644 --- a/urbansim_templates/data/__init__.py +++ b/urbansim_templates/data/__init__.py @@ -1,4 +1,4 @@ -from .column_from_broadcast import ColumnFromBroadcast -from .column_from_expression import ColumnFromExpression -from .load_table import LoadTable -from .save_table import SaveTable +from .column_broadcast import ColumnFromBroadcast +from .column_expression import ColumnFromExpression +from .table_load import LoadTable +from .table_save import SaveTable diff --git a/urbansim_templates/data/column_from_broadcast.py b/urbansim_templates/data/column_broadcast.py similarity index 100% rename from urbansim_templates/data/column_from_broadcast.py rename to urbansim_templates/data/column_broadcast.py diff --git a/urbansim_templates/data/column_from_expression.py b/urbansim_templates/data/column_expression.py similarity index 100% rename from urbansim_templates/data/column_from_expression.py rename to urbansim_templates/data/column_expression.py diff --git a/urbansim_templates/data/load_table.py b/urbansim_templates/data/table_load.py similarity index 100% rename from urbansim_templates/data/load_table.py rename to urbansim_templates/data/table_load.py diff --git a/urbansim_templates/data/save_table.py b/urbansim_templates/data/table_save.py similarity index 100% rename from urbansim_templates/data/save_table.py rename to urbansim_templates/data/table_save.py From c3c72afc8066151db775170c7bee925174ebcfb1 Mon Sep 17 00:00:00 2001 From: Sam Maurer Date: Mon, 1 Apr 2019 14:47:50 -0700 Subject: [PATCH 6/8] Work in progress --- tests/test_column_broadcast.py | 154 +++++++++++++++++++-------------- 1 file changed, 87 insertions(+), 67 deletions(-) diff --git a/tests/test_column_broadcast.py b/tests/test_column_broadcast.py index 29f04f3..5981135 100644 --- a/tests/test_column_broadcast.py +++ b/tests/test_column_broadcast.py @@ -18,78 +18,29 @@ def orca_session(): orca.clear_all() modelmanager.initialize() - d1 = {'id': np.arange(5), - 'a': np.random.random(5), - 'b': np.random.choice(np.arange(20), size=5)} + d = {'building_id': [1,2,3,4], 'value': [4,4,4,4]} + df = pd.DataFrame(d).set_index('building_id') + orca.add_table('buildings', df) + + d = {'household_id': [1,2,3], 'building_id': [2,3,4]} + df = pd.DataFrame(d).set_index('household_id') + orca.add_table('households', df) + + + +############################### +## BEHAVIOR OF TEMPLATE + + + + + + - df = pd.DataFrame(d1).set_index('id') - orca.add_table('obs', df) - - # TO DO: add another table -def test_template_validity(): - """ - Check template conforms to basic spec. - - """ - assert validate_template(ColumnFromBroadcast) -# def test_missing_colname(orca_session): -# """ -# Missing column_name should raise a ValueError. -# -# """ -# c = ColumnFromExpression() -# c.table = 'tab' -# c.expression = 'a' -# -# try: -# c.run() -# except ValueError as e: -# print(e) -# return -# -# pytest.fail() -# -# -# def test_missing_table(orca_session): -# """ -# Missing table should raise a ValueError. -# -# """ -# c = ColumnFromExpression() -# c.column_name = 'col' -# c.expression = 'a' -# -# try: -# c.run() -# except ValueError as e: -# print(e) -# return -# -# pytest.fail() -# -# -# def test_missing_expression(orca_session): -# """ -# Missing expression should raise a ValueError. -# -# """ -# c = ColumnFromExpression() -# c.column_name = 'col' -# c.table = 'tab' -# -# try: -# c.run() -# except ValueError as e: -# print(e) -# return -# -# pytest.fail() -# -# # def test_expression(orca_session): # """ # Check that column is created and expression evaluated correctly. @@ -191,3 +142,72 @@ def test_template_validity(): # d.run() # assert('d' in orca.get_table('obs').columns) # + + + + +############################### +## SPEC CONFORMANCE AND BAD DATA INPUTS + +def test_template_validity(): + """ + Check template conforms to basic spec. + + """ + assert validate_template(ColumnFromBroadcast) + + +# def test_missing_colname(orca_session): +# """ +# Missing column_name should raise a ValueError. +# +# """ +# c = ColumnFromExpression() +# c.table = 'tab' +# c.expression = 'a' +# +# try: +# c.run() +# except ValueError as e: +# print(e) +# return +# +# pytest.fail() +# +# +# def test_missing_table(orca_session): +# """ +# Missing table should raise a ValueError. +# +# """ +# c = ColumnFromExpression() +# c.column_name = 'col' +# c.expression = 'a' +# +# try: +# c.run() +# except ValueError as e: +# print(e) +# return +# +# pytest.fail() +# +# +# def test_missing_expression(orca_session): +# """ +# Missing expression should raise a ValueError. +# +# """ +# c = ColumnFromExpression() +# c.column_name = 'col' +# c.table = 'tab' +# +# try: +# c.run() +# except ValueError as e: +# print(e) +# return +# +# pytest.fail() +# +# From f3ff4d7aaae3bdaf92867036576853b9e3e83a76 Mon Sep 17 00:00:00 2001 From: Sam Maurer Date: Thu, 4 Apr 2019 16:18:04 -0700 Subject: [PATCH 7/8] Fixing deprecation warnings --- tests/pytest.ini | 1 + urbansim_templates/utils.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/pytest.ini b/tests/pytest.ini index b34a956..5983846 100644 --- a/tests/pytest.ini +++ b/tests/pytest.ini @@ -4,6 +4,7 @@ filterwarnings = ignore:::urbansim ignore:::pandas ignore:::past + ignore:::patsy ignore:::prettytable ignore:::scipy ignore:::statsmodels diff --git a/urbansim_templates/utils.py b/urbansim_templates/utils.py index 7879ffb..3f803a6 100644 --- a/urbansim_templates/utils.py +++ b/urbansim_templates/utils.py @@ -365,7 +365,7 @@ def cols_in_expression(expression): cols : list of str """ - return re.findall('[a-zA-Z_][a-zA-Z0-9_]*(?!\()', expression) + return re.findall(r'[a-zA-Z_][a-zA-Z0-9_]*(?!\()', expression) def trim_cols(df, columns=None): From fe4e785f5a68dbd28b113d4fae16a62830f38cd8 Mon Sep 17 00:00:00 2001 From: Sam Maurer Date: Wed, 24 Apr 2019 10:45:24 -0700 Subject: [PATCH 8/8] Cleaning up tests --- tests/test_binary_logit.py | 2 ++ tests/test_large_multinomial_logit.py | 2 ++ tests/test_regression.py | 2 ++ tests/test_segmented_large_multinomial_logit.py | 2 ++ tests/test_small_multinomial_logit.py | 2 ++ tests/{test_data_load.py => test_table_load.py} | 0 tests/{test_data_save.py => test_table_save.py} | 0 7 files changed, 10 insertions(+) rename tests/{test_data_load.py => test_table_load.py} (100%) rename tests/{test_data_save.py => test_table_save.py} (100%) diff --git a/tests/test_binary_logit.py b/tests/test_binary_logit.py index 86dacef..2d49445 100644 --- a/tests/test_binary_logit.py +++ b/tests/test_binary_logit.py @@ -10,6 +10,8 @@ @pytest.fixture def orca_session(): + orca.clear_all() + d1 = {'a': np.random.random(100), 'b': np.random.randint(2, size=100)} diff --git a/tests/test_large_multinomial_logit.py b/tests/test_large_multinomial_logit.py index 2961ce9..a783765 100644 --- a/tests/test_large_multinomial_logit.py +++ b/tests/test_large_multinomial_logit.py @@ -12,6 +12,8 @@ @pytest.fixture def orca_session(): + orca.clear_all() + d1 = {'oid': np.arange(10), 'obsval': np.random.random(10), 'choice': np.random.choice(np.arange(20), size=10)} diff --git a/tests/test_regression.py b/tests/test_regression.py index 1220395..2ab3586 100644 --- a/tests/test_regression.py +++ b/tests/test_regression.py @@ -10,6 +10,8 @@ @pytest.fixture def orca_session(): + orca.clear_all() + d1 = {'a': np.random.random(100), 'b': np.random.random(100)} diff --git a/tests/test_segmented_large_multinomial_logit.py b/tests/test_segmented_large_multinomial_logit.py index 0cfc8b7..0e09fbb 100644 --- a/tests/test_segmented_large_multinomial_logit.py +++ b/tests/test_segmented_large_multinomial_logit.py @@ -16,6 +16,8 @@ def orca_session(): Set up a clean Orca session with a couple of data tables. """ + orca.clear_all() + d1 = {'oid': np.arange(100), 'group': np.random.choice(['A','B','C'], size=100), 'int_group': np.random.choice([3,4], size=100), diff --git a/tests/test_small_multinomial_logit.py b/tests/test_small_multinomial_logit.py index 4e35511..8cd5e14 100644 --- a/tests/test_small_multinomial_logit.py +++ b/tests/test_small_multinomial_logit.py @@ -11,6 +11,8 @@ @pytest.fixture def orca_session(): + orca.clear_all() + d1 = {'id': np.arange(100), 'building_id': np.arange(100), 'a': np.random.random(100), diff --git a/tests/test_data_load.py b/tests/test_table_load.py similarity index 100% rename from tests/test_data_load.py rename to tests/test_table_load.py diff --git a/tests/test_data_save.py b/tests/test_table_save.py similarity index 100% rename from tests/test_data_save.py rename to tests/test_table_save.py