Skip to content

Commit

Permalink
Merge branch 'master' into roll-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
roll committed Sep 4, 2017
2 parents b054965 + 547c776 commit 685d973
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 21 deletions.
42 changes: 32 additions & 10 deletions datapackage/package.py
Expand Up @@ -323,7 +323,7 @@ def safe(self):

# Deprecate
warnings.warn(
'DataPackage.safe is deprecated. '
'Property "package.safe" is deprecated. '
'Now it\'s always safe.',
UserWarning)

Expand All @@ -336,7 +336,7 @@ def schema(self):

# Deprecate
warnings.warn(
'DataPackage.schema is deprecated.',
'Property "package.schema" is deprecated.',
UserWarning)

return self.__profile
Expand All @@ -348,7 +348,7 @@ def attributes(self):

# Deprecate
warnings.warn(
'DataPackage.attributes is deprecated.',
'Property "package.attributes" is deprecated.',
UserWarning)

# Get attributes
Expand All @@ -367,7 +367,7 @@ def required_attributes(self):

# Deprecate
warnings.warn(
'DataPackage.attributes_attributes is deprecated.',
'Property "package.required_attributes" is deprecated.',
UserWarning)
required = ()

Expand All @@ -382,35 +382,57 @@ def required_attributes(self):

def validate(self):
""""Validate this Data Package.
"""

Raises:
ValidationError: If the Data Package is invalid.
# Deprecate
warnings.warn(
'Property "package.validate" is deprecated.',
UserWarning)

"""
descriptor = self.to_dict()
self.profile.validate(descriptor)

def iter_errors(self):
""""Lazily yields each ValidationError for the received data dict.
"""

Returns:
iter: ValidationError for each error in the data.
# Deprecate
warnings.warn(
'Property "package.iter_errors" is deprecated.',
UserWarning)

"""
return self.profile.iter_errors(self.to_dict())

@property
def base_path(self):
""""str: The base path of this Data Package (can be None).
"""

# Deprecate
warnings.warn(
'Property "package.base_path" is deprecated.',
UserWarning)

return self.__base_path

def to_dict(self):
""""dict: Convert this Data Package to dict.
"""

# Deprecate
warnings.warn(
'Property "package.to_dict" is deprecated.',
UserWarning)

return copy.deepcopy(self.descriptor)

def to_json(self):
""""str: Convert this Data Package to a JSON string.
"""

# Deprecate
warnings.warn(
'Property "package.to_json" is deprecated.',
UserWarning)

return json.dumps(self.descriptor)
18 changes: 12 additions & 6 deletions datapackage/profile.py
Expand Up @@ -7,6 +7,7 @@
import six
import copy
import json
import warnings
import requests
import jsonschema
import datapackage.registry
Expand Down Expand Up @@ -115,18 +116,23 @@ def __dir__(self):

def iter_errors(self, data):
"""Lazily yields each ValidationError for the received data dict.
"""

Args:
data (dict): The data to be validated.
Returns:
iter: ValidationError for each error in the data.
# Deprecate
warnings.warn(
'Property "profile.iter_errors" is deprecated.',
UserWarning)

"""
for error in self._validator.iter_errors(data):
yield error

def to_dict(self):
"""dict: Convert this :class:`.Schema` to dict.
"""

# Deprecate
warnings.warn(
'Property "profile.to_dict" is deprecated.',
UserWarning)

return copy.deepcopy(self._schema)
26 changes: 22 additions & 4 deletions datapackage/resource.py
Expand Up @@ -152,7 +152,7 @@ def iter(self, relations=False, **options):
# Error for non tabular
if not self.tabular:
message = 'Methods iter/read are not supported for non tabular data'
raise exceptions.DataPackageError(message)
raise exceptions.DataPackageException(message)

# Get relations
if relations:
Expand All @@ -167,7 +167,7 @@ def read(self, relations=False, **options):
# Error for non tabular
if not self.tabular:
message = 'Methods iter/read are not supported for non tabular data'
raise exceptions.DataPackageError(message)
raise exceptions.DataPackageException(message)

# Get relations
if relations:
Expand All @@ -188,7 +188,7 @@ def raw_iter(self, stream=False):
# Error for inline
if self.inline:
message = 'Methods raw_iter/raw_read are not supported for inline data'
raise exceptions.DataPackageError(message)
raise exceptions.DataPackageException(message)

# Get filelike
if self.multipart:
Expand Down Expand Up @@ -351,8 +351,26 @@ def __get_relations(self):

@property
def table(self):

# Deprecate
warnings.warn(
'Property "resource.table" is deprecated. '
'Please use "resource.iter/read" directly.',
UserWarning)

return self.__get_table()

@property
def data(self):

# Deprecate
warnings.warn(
'Property "resource.data" is deprecated. '
'Please use "resource.read(keyed=True)" instead.',
UserWarning)

return self.read(keyed=True)


# Internal

Expand Down Expand Up @@ -417,7 +435,7 @@ def _inspect_source(data, path, base_path):
inspection['format'] = os.path.splitext(filename)[1][1:]
inspection['name'] = os.path.splitext(filename)[0]
inspection['mediatype'] = 'text/%s' % inspection['format']
inspection['tabular'] = inspection['format'] == 'csv'
inspection['tabular'] = inspection['format'] in ['csv', 'tsv', 'xls', 'xlsx']

# Multipart Local/Remote
elif len(path) > 1:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -28,7 +28,7 @@ def read(*paths):
'jsonschema>=2.5,<3.0',
'unicodecsv>=0.14,<2.0',
'jsonpointer>=1.10,<2.0',
'tableschema>=1.0.0a14,<2.0',
'tableschema>=1.0,<2.0',
'tabulator>=1.3,<2.0',
# TODO: remove after this issue will be resolved
# https://github.com/frictionlessdata/implementations/issues/11
Expand Down
11 changes: 11 additions & 0 deletions tests/test_resource.py
Expand Up @@ -532,6 +532,17 @@ def test_descriptor_table_tabular_dialect_header_false():
]


# Deprecated

def test_data():
resource = Resource({'path': 'data/cities.tsv'})
assert resource.data[0:3] == [
{'Area': '1807.92', 'Name': 'Acrelândia', 'Population': '12538', 'State': 'AC'},
{'Area': '186.53', 'Name': 'Boca da Mata', 'Population': '25776', 'State': 'AL'},
{'Area': '242.62', 'Name': 'Capela', 'Population': '17077', 'State': 'AL'},
]


# Helpers

@pytest.fixture
Expand Down

0 comments on commit 685d973

Please sign in to comment.