Skip to content

Commit

Permalink
Merge pull request #49 from bryanwweber/add-skip-validation
Browse files Browse the repository at this point in the history
Add skip validation
  • Loading branch information
kyleniemeyer authored Apr 21, 2017
2 parents db1bab0 + d21808c commit 97294b7
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 33 deletions.
6 changes: 0 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,12 @@ language: generic

matrix:
include:
- os: linux
env: PYTHON="2.7"

- os: linux
env: PYTHON="3.5"

- os: linux
env: PYTHON="3.6"

- os: osx
env: PYTHON="2.7"

- os: osx
env: PYTHON="3.5"

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Added
- Add `skip_validation` keyword argument to the `ChemKED` initializer

### Fixed

Expand Down
3 changes: 0 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ environment:
secure: agG4yvYjpYq1nzjLhnZ92Z6ZFVM+KA5JyYIYwX2YVQxpuRj7myqJNfttUVTqynIg

matrix:
- PYTHON_LOC: "C:\\Miniconda-x64"
PYTHON_VERSION: "2.7"

- PYTHON_LOC: "C:\\Miniconda36-x64"
PYTHON_VERSION: "3.5"

Expand Down
2 changes: 1 addition & 1 deletion conda.recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ build:

requirements:
build:
- python >=2.7,<3|>=3.5,{{PY_VER}}*
- python >=3.5,{{PY_VER}}*
- setuptools

run:
Expand Down
42 changes: 20 additions & 22 deletions pyked/chemked.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
"""
Main ChemKED module
"""
from __future__ import print_function, division
from collections import namedtuple
from warnings import warn
from copy import deepcopy
from sys import version_info

import numpy as np

Expand All @@ -14,29 +12,26 @@
from .utils import Q_

VolumeHistory = namedtuple('VolumeHistory', ['time', 'volume'])
if version_info.major >= 3:
VolumeHistory.__doc__ = 'Time history of the volume in an RCM experiment'
VolumeHistory.time.__doc__ = '(`~numpy.ndarray`): the time during the experiment'
VolumeHistory.volume.__doc__ = '(`~numpy.ndarray`): the volume during the experiment'
VolumeHistory.__doc__ = 'Time history of the volume in an RCM experiment'
VolumeHistory.time.__doc__ = '(`~numpy.ndarray`): the time during the experiment'
VolumeHistory.volume.__doc__ = '(`~numpy.ndarray`): the volume during the experiment'

Reference = namedtuple('Reference',
['volume', 'journal', 'doi', 'authors', 'detail', 'year', 'pages'])
if version_info.major >= 3:
Reference.__doc__ = 'Information about the article or report where the data can be found'
Reference.volume.__doc__ = '(`str`) The journal volume'
Reference.journal.__doc__ = '(`str`) The name of the journal'
Reference.doi.__doc__ = '(`str`) The Digital Object Identifier of the article'
Reference.authors.__doc__ = '(`list`) The list of authors of the article'
Reference.detail.__doc__ = '(`str`) Detail about where the data can be found in the article'
Reference.year.__doc__ = '(`str`) The year the article was published'
Reference.pages.__doc__ = '(`str`) The pages in the journal where the article was published'
Reference.__doc__ = 'Information about the article or report where the data can be found'
Reference.volume.__doc__ = '(`str`) The journal volume'
Reference.journal.__doc__ = '(`str`) The name of the journal'
Reference.doi.__doc__ = '(`str`) The Digital Object Identifier of the article'
Reference.authors.__doc__ = '(`list`) The list of authors of the article'
Reference.detail.__doc__ = '(`str`) Detail about where the data can be found in the article'
Reference.year.__doc__ = '(`str`) The year the article was published'
Reference.pages.__doc__ = '(`str`) The pages in the journal where the article was published'

Apparatus = namedtuple('Apparatus', ['kind', 'institution', 'facility'])
if version_info.major >= 3:
Apparatus.__doc__ = 'Information about the experimental apparatus used to generate the data'
Apparatus.kind.__doc__ = '(`str`) The kind of experimental apparatus'
Apparatus.institution.__doc__ = '(`str`) The institution where the experiment is located'
Apparatus.facility.__doc__ = '(`str`) The particular experimental facility at the location'
Apparatus.__doc__ = 'Information about the experimental apparatus used to generate the data'
Apparatus.kind.__doc__ = '(`str`) The kind of experimental apparatus'
Apparatus.institution.__doc__ = '(`str`) The institution where the experiment is located'
Apparatus.facility.__doc__ = '(`str`) The particular experimental facility at the location'


class ChemKED(object):
Expand All @@ -50,6 +45,8 @@ class ChemKED(object):
yaml_file (`str`, optional): The filename of the YAML database in ChemKED format.
dict_input (`str`, optional): A dictionary with the parsed ouput of YAML file in ChemKED
format.
skip_validation (`bool`, optional): Whether validation of the ChemKED should be done. Must
be supplied as a keyword-argument.
Attributes:
datapoints (`list`): List of `DataPoint` objects storing each datapoint in the database.
Expand All @@ -64,7 +61,7 @@ class ChemKED(object):
file_author (`dict`): Information about the author of the ChemKED database file.
file_version (`str`): Version of the ChemKED database file.
"""
def __init__(self, yaml_file=None, dict_input=None):
def __init__(self, yaml_file=None, dict_input=None, *, skip_validation=False):
if yaml_file is not None:
with open(yaml_file, 'r') as f:
properties = yaml.safe_load(f)
Expand All @@ -73,7 +70,8 @@ def __init__(self, yaml_file=None, dict_input=None):
else:
raise NameError("ChemKED needs either a YAML filename or dictionary as input.")

self.validate_yaml(properties)
if not skip_validation:
self.validate_yaml(properties)

self.datapoints = []
for point in properties['datapoints']:
Expand Down
8 changes: 7 additions & 1 deletion pyked/tests/test_chemked.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
from ..chemked import ChemKED, DataPoint
from ..utils import Q_

warnings.simplefilter("always")
warnings.simplefilter('always')


class TestChemKED(object):
"""
Expand All @@ -25,6 +26,11 @@ def test_create_chemked(self):
filename = pkg_resources.resource_filename(__name__, file_path)
ChemKED(filename)

def test_skip_validation(self):
file_path = os.path.join('testfile_bad.yaml')
filename = pkg_resources.resource_filename(__name__, file_path)
ChemKED(filename, skip_validation=True)

def test_datapoints(self):
file_path = os.path.join('testfile_st.yaml')
filename = pkg_resources.resource_filename(__name__, file_path)
Expand Down

0 comments on commit 97294b7

Please sign in to comment.