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

Bulk reformatting code with the black formatter. #102

Merged
merged 1 commit into from
Jul 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions csvqb/csvqb/models/cube/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@


class CatalogMetadataBase(ABC):

def __init__(self,
title: str,
description: Optional[str] = None,
issued: Optional[datetime] = None):
def __init__(
self,
title: str,
description: Optional[str] = None,
issued: Optional[datetime] = None,
):
self.title: str = title
self.description: Optional[str] = description
self.issued: Optional[datetime] = issued
Expand Down
25 changes: 18 additions & 7 deletions csvqb/csvqb/models/cube/columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,41 @@


class CsvColumn(ABC):

def __init__(self, csv_column_title: str, uri_safe_identifier: Optional[str] = None):
def __init__(
self, csv_column_title: str, uri_safe_identifier: Optional[str] = None
):
self.csv_column_title: str = csv_column_title
self.uri_safe_identifier: str = uri_safe(csv_column_title) if uri_safe_identifier is None else uri_safe_identifier
self.uri_safe_identifier: str = (
uri_safe(csv_column_title)
if uri_safe_identifier is None
else uri_safe_identifier
)

@abstractmethod
def __str__(self) -> str:
pass

@abstractmethod
def validate(self, column_data: Optional[pd.Series] = None) -> List[ValidationError]:
def validate(
self, column_data: Optional[pd.Series] = None
) -> List[ValidationError]:
pass


class SuppressedCsvColumn(CsvColumn):
"""
A column which is only defined in the CSV and should not be propagated.
A column which is only defined in the CSV and should not be propagated.
"""

def __init__(self, csv_column_title: str, uri_safe_identifier: Optional[str] = None):
def __init__(
self, csv_column_title: str, uri_safe_identifier: Optional[str] = None
):
CsvColumn.__init__(self, csv_column_title, uri_safe_identifier)

def __str__(self) -> str:
return f"SuppressedCsvColumn('{self.csv_column_title}')"

def validate(self, column_data: Optional[pd.Series] = None) -> List[ValidationError]:
def validate(
self, column_data: Optional[pd.Series] = None
) -> List[ValidationError]:
return [] # TODO: implement this
36 changes: 19 additions & 17 deletions csvqb/csvqb/models/cube/csvqb/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,24 @@


class CatalogMetadata(CatalogMetadataBase):

def __init__(self,
title: str,
uri_safe_identifier: Optional[str] = None,
summary: Optional[str] = None,
description: Optional[str] = None,
creator_uri: Optional[str] = None,
publisher_uri: Optional[str] = None,
issued: Optional[datetime] = None,
theme_uris: List[str] = [],
keywords: List[str] = [],
landing_page_uri: Optional[str] = None,
license_uri: Optional[str] = None,
public_contact_point_uri: Optional[str] = None):
CatalogMetadataBase.__init__(self, title, description=description, issued=issued)
def __init__(
self,
title: str,
uri_safe_identifier: Optional[str] = None,
summary: Optional[str] = None,
description: Optional[str] = None,
creator_uri: Optional[str] = None,
publisher_uri: Optional[str] = None,
issued: Optional[datetime] = None,
theme_uris: List[str] = [],
keywords: List[str] = [],
landing_page_uri: Optional[str] = None,
license_uri: Optional[str] = None,
public_contact_point_uri: Optional[str] = None,
):
CatalogMetadataBase.__init__(
self, title, description=description, issued=issued
)
self.uri_safe_identifier: str = uri_safe_identifier or uri_safe(title)
self.summary: Optional[str] = summary
self.creator_uri: Optional[str] = creator_uri
Expand All @@ -33,5 +36,4 @@ def __init__(self,
self.public_contact_point_uri: Optional[str] = public_contact_point_uri

def validate(self) -> List[ValidationError]:
return CatalogMetadataBase.validate(self) \
+ [] # TODO: augment this
return CatalogMetadataBase.validate(self) + [] # TODO: augment this
22 changes: 14 additions & 8 deletions csvqb/csvqb/models/cube/csvqb/columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,28 @@
from csvqb.models.cube.columns import CsvColumn


QbColumnarDsdType = TypeVar("QbColumnarDsdType", bound=ColumnarQbDataStructureDefinition, covariant=True)
QbColumnarDsdType = TypeVar(
"QbColumnarDsdType", bound=ColumnarQbDataStructureDefinition, covariant=True
)


class QbColumn(CsvColumn, Generic[QbColumnarDsdType]):
"""
A CSV column and the qb components it relates to.
A CSV column and the qb components it relates to.
"""

def __init__(self,
csv_column_title: str,
component: QbColumnarDsdType,
output_uri_template: Optional[str] = None,
uri_safe_identifier: Optional[str] = None):
def __init__(
self,
csv_column_title: str,
component: QbColumnarDsdType,
output_uri_template: Optional[str] = None,
uri_safe_identifier: Optional[str] = None,
):
CsvColumn.__init__(self, csv_column_title, uri_safe_identifier)
if not isinstance(component, ColumnarQbDataStructureDefinition):
raise Exception(f"{component} of type {type(component)} is not a valid columnar component.")
raise Exception(
f"{component} of type {type(component)} is not a valid columnar component."
)
self.component: QbColumnarDsdType = component
self.output_uri_template: Optional[str] = output_uri_template

Expand Down
58 changes: 32 additions & 26 deletions csvqb/csvqb/models/cube/csvqb/components/attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def __init__(self, is_required: bool):


class ExistingQbAttribute(QbAttribute):

def __init__(self, uri: str, is_required: bool = False):
QbAttribute.__init__(self, is_required)
self.attribute_uri: str = uri
Expand All @@ -33,39 +32,46 @@ def validate_data(self, data: pd.Series) -> List[ValidationError]:


class NewQbAttribute(QbAttribute):

def __init__(self,
label: str,
uri_safe_identifier: Optional[str] = None,
description: Optional[str] = None,
code_list: Optional[QbCodeList] = None,
parent_attribute_uri: Optional[str] = None,
source_uri: Optional[str] = None,
is_required: bool = False):
def __init__(
self,
label: str,
uri_safe_identifier: Optional[str] = None,
description: Optional[str] = None,
code_list: Optional[QbCodeList] = None,
parent_attribute_uri: Optional[str] = None,
source_uri: Optional[str] = None,
is_required: bool = False,
):
QbAttribute.__init__(self, is_required)
self.label: str = label
self.uri_safe_identifier: str = uri_safe_identifier if uri_safe_identifier is not None else uri_safe(label)
self.uri_safe_identifier: str = (
uri_safe_identifier if uri_safe_identifier is not None else uri_safe(label)
)
self.description: Optional[str] = description
self.code_list: Optional[QbCodeList] = code_list
self.parent_attribute_uri: Optional[str] = parent_attribute_uri
self.source_uri: Optional[str] = source_uri

@staticmethod
def from_data(label: str,
data: PandasDataTypes,
uri_safe_identifier: Optional[str] = None,
description: Optional[str] = None,
parent_attribute_uri: Optional[str] = None,
source_uri: Optional[str] = None,
is_required: bool = False):

return NewQbAttribute(label,
uri_safe_identifier=uri_safe_identifier,
description=description,
code_list=NewQbCodeList.from_data(CatalogMetadata(label), data),
parent_attribute_uri=parent_attribute_uri,
source_uri=source_uri,
is_required=is_required)
def from_data(
label: str,
data: PandasDataTypes,
uri_safe_identifier: Optional[str] = None,
description: Optional[str] = None,
parent_attribute_uri: Optional[str] = None,
source_uri: Optional[str] = None,
is_required: bool = False,
):

return NewQbAttribute(
label,
uri_safe_identifier=uri_safe_identifier,
description=description,
code_list=NewQbCodeList.from_data(CatalogMetadata(label), data),
parent_attribute_uri=parent_attribute_uri,
source_uri=source_uri,
is_required=is_required,
)

def __str__(self) -> str:
return f"NewQbAttribute('{self.label}')"
Expand Down
40 changes: 21 additions & 19 deletions csvqb/csvqb/models/cube/csvqb/components/codelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ def validate_data(self, data: pd.Series) -> List[ValidationError]:


class NewQbConcept:

def __init__(self,
label: str,
code: Optional[str] = None,
parent_code: Optional[str] = None,
sort_order: Optional[int] = None,
description: Optional[str] = None):
def __init__(
self,
label: str,
code: Optional[str] = None,
parent_code: Optional[str] = None,
sort_order: Optional[int] = None,
description: Optional[str] = None,
):
self.label: str = label
self.code: str = code or uri_safe(label)
self.parent_code: Optional[str] = parent_code
Expand All @@ -58,10 +59,12 @@ class NewQbCodeList(QbCodeList):
Contains the metadata necessary to create a new skos:ConceptScheme which is local to a dataset.
"""

def __init__(self,
metadata: CatalogMetadata,
concepts: List[NewQbConcept],
variant_of_uris: List[str] = []):
def __init__(
self,
metadata: CatalogMetadata,
concepts: List[NewQbConcept],
variant_of_uris: List[str] = [],
):
self.metadata: CatalogMetadata = metadata
self.concepts: List[NewQbConcept] = concepts
self.variant_of_uris: List[str] = variant_of_uris # For xkos:variant usage.
Expand All @@ -70,18 +73,17 @@ def __str__(self) -> str:
return f"NewQbCodeList('{self.metadata.title}')"

@staticmethod
def from_data(metadata: CatalogMetadata,
data: PandasDataTypes,
variant_of_uris: List[str] = []) -> "NewQbCodeList":
def from_data(
metadata: CatalogMetadata,
data: PandasDataTypes,
variant_of_uris: List[str] = [],
) -> "NewQbCodeList":
columnar_data = pandas_input_to_columnar_str(data)
concepts = [NewQbConcept(c) for c in sorted(set(columnar_data))]
return NewQbCodeList(metadata,
concepts,
variant_of_uris=variant_of_uris)
return NewQbCodeList(metadata, concepts, variant_of_uris=variant_of_uris)

def validate(self) -> List[ValidationError]:
return self.metadata.validate() \
+ [] # TODO: augment this.
return self.metadata.validate() + [] # TODO: augment this.

def validate_data(self, data: pd.Series) -> List[ValidationError]:
return [] # TODO: implement this.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

class QbDataStructureDefinition(ABC):
"""
Base class for entities holding information necessary to generate one or many qb DataStructureDefinition (DSD)
components.
Base class for entities holding information necessary to generate one or many qb DataStructureDefinition (DSD)
components.
"""

@abstractmethod
Expand All @@ -30,14 +30,15 @@ def __str__(self) -> str:

class ColumnarQbDataStructureDefinition(QbDataStructureDefinition, ABC):
"""
Base class representing Qb Data Structure Definitions which can be directly attached to a pd.DataFrame column.
Base class representing Qb Data Structure Definitions which can be directly attached to a pd.DataFrame column.
"""

pass


class MultiQbDataStructureDefinition(ColumnarQbDataStructureDefinition, ABC):
"""
Base class representing an entity which defines a group of `QbDataStructureDefinition`s
Base class representing an entity which defines a group of `QbDataStructureDefinition`s
"""

@abstractmethod
Expand Down
Loading