Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[0.2.dev5] Template for column from expression #105

Merged
merged 12 commits into from
Mar 29, 2019
Merged

Conversation

smmaurer
Copy link
Member

@smmaurer smmaurer commented Mar 12, 2019

This PR adds a template to register a column of derived data with Orca, based on an expression. This is the first use case from issue #98.

New template

  • urbansim_templates.data.ColumnFromExpression()

The expression is passed to df.eval() and can refer to other columns in the same table, including stand-alone columns that have not yet been evaluated. It supports arithmetic and math functions including sqrt, abs, log, exp, log1p, and expm1.

More info about the expression parsing:

Template-specific parameters:

  • column_name
  • table
  • expression
  • data_type (optional)
  • missing_values (optional)
  • cache (optional)
  • cache_scope (optional)

Versioning

  • 0.2.dev5

To do before merging

  • finish tests
  • add check for column validity in run() method
  • finalize versioning
  • update docs and changelog


"""
if self.column_name is None:
raise ValueError("Please provide a column name")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line uses double quotes but there are single quotes in other parts of the file. In the future we can use pylint to ensure uniform code style.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use double quotes for natural-language messages and single quotes for strings that are more like data, i think. Not sure if this is a standard or just a habit i picked up, though! We can see what pylint wants.

raise ValueError("Please provide a column name")

if self.table is None:
raise ValueError("Please provide a table")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

raise ValueError("Please provide a table")

if self.expression is None:
raise ValueError("Please provide an expression")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

@smmaurer smmaurer changed the title Template for column from expression [0.2.dev5] Template for column from expression Mar 29, 2019
@smmaurer smmaurer marked this pull request as ready for review March 29, 2019 18:48
@smmaurer smmaurer merged commit f5bd26e into master Mar 29, 2019
@smmaurer smmaurer deleted the col-from-expression branch March 29, 2019 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants