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

Python documentation #991

Merged
merged 7 commits into from
Oct 28, 2024
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
3 changes: 2 additions & 1 deletion bindings/python/dlite-collection-python.i
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class Collection(Instance):
Relations are (s, p, o, d=None)-triples with an optional fourth field
`d`, specifying the datatype of the object. The datatype may have the
following values:
- None: object is an IRI.
- Starts with '@': object is a language-tagged plain literal.
The language identifier follows the '@'-sign.
Expand All @@ -85,7 +86,7 @@ class Collection(Instance):
Arguments:
src: Storage instance | url | driver
location: str
location:
File path to load from when `src` is a driver.
options: str
Options passed to the storage plugin when `src` is a driver.
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/dlite-entity-python.i
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ def get_instance(
protocol+driver://location?options#id
protocol://location?driver=<driver>;options#id

where `protocol`, `driver`, `location`, `options` and `id are
where `protocol`, `driver`, `location`, `options` and `id` are
documented in the load() method.

If `metaid` is provided, the instance is tried mapped to this
Expand Down
6 changes: 3 additions & 3 deletions bindings/python/dlite-misc-python.i
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ class errctl():
shown/hidden.
filename: Filename to redirect errors to. The following values
are handled specially:
- "None" or empty: No output is written.
- "<stderr>": Write errors to stderr (default).
- "<stdout>": Write errors to stdout.
- "None" or empty: No output is written.
- "<stderr>": Write errors to stderr (default).
- "<stdout>": Write errors to stdout.
"""
def __init__(self, hide=(), show=(), filename="<stderr>"):
Expand Down
46 changes: 23 additions & 23 deletions bindings/python/quantity.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@

""" Define the singleton QuantityHelper to work with pint Quantity and dlite
instance properties.
"""Define the singleton QuantityHelper to work with pint Quantity and dlite
instance properties.
"""

from typing import Any
import numpy as np
HAS_PINT = True
try:
import pint
except Exception:
HAS_PINT = False
from dlite.testutils import importcheck

pint = importcheck("pint")


DLITE_QUANTITY_TYPES = [
'int', 'float', 'double', 'uint',
Expand All @@ -21,8 +19,16 @@


class QuantityHelper:
"""Singleton class for working with pint Quantity and dlite instance
properties.
"""

def __init__(self):
if not pint:
raise RuntimeError(
'you must install "pint" to work with quantities, '
'try: pip install pint'
)
self.__dict__['_instance'] = None
self.__dict__['_registry'] = None

Expand All @@ -46,7 +52,7 @@ def _get_unit_as_string(self, unit: Any) -> str:
unit_string = str(unit)
return unit_string.replace('%', 'percent')

def __getitem__(self, name: str) -> pint.Quantity:
def __getitem__(self, name: str) -> "pint.Quantity":
p = self._get_property(name)
u = self._get_unit_as_string(p.unit)
return self.quantity(self._instance[name], u)
Expand Down Expand Up @@ -105,15 +111,15 @@ def get(self, *names):
return None

@property
def unit_registry(self) -> pint.UnitRegistry:
def unit_registry(self) -> "pint.UnitRegistry":
""" Returns the current pint UnitRegistry object """
return self._registry.get()

def quantity(self, magnitude, unit) -> pint.Quantity:
def quantity(self, magnitude, unit) -> "pint.Quantity":
""" Return a pint.Quantity object """
return self._registry.Quantity(magnitude, unit)

def parse(self, value: Any) -> pint.Quantity:
def parse(self, value: Any) -> "pint.Quantity":
""" Parse the given value and return a pint.Quantity object """
if isinstance(value, (pint.Quantity, self._registry.Quantity)):
return value
Expand All @@ -129,8 +135,8 @@ def parse(self, value: Any) -> pint.Quantity:
else:
return self.quantity(value, '')

def parse_expression(self, value: str) -> pint.Quantity:
""" Parse an expression (str) and return a pint.Quantity object """
def parse_expression(self, value: str) -> "pint.Quantity":
"""Parse an expression (str) and return a pint.Quantity object """
result = None
if value:
value_str = self._get_unit_as_string(value)
Expand Down Expand Up @@ -171,12 +177,6 @@ def to_dict(self, names=None, value_type='quantity', fmt=''):

def get_quantity_helper(instance):
global quantity_helper
if HAS_PINT:
if quantity_helper is None:
quantity_helper = QuantityHelper()
return quantity_helper(instance)
else:
raise RuntimeError(
'you must install "pint" to work with quantities, '
'try: pip install pint'
)
if quantity_helper is None:
quantity_helper = QuantityHelper()
return quantity_helper(instance)
148 changes: 0 additions & 148 deletions bindings/python/triplestore/README.md

This file was deleted.

13 changes: 0 additions & 13 deletions bindings/python/triplestore/__init__.py

This file was deleted.

31 changes: 0 additions & 31 deletions bindings/python/triplestore/test_units.py

This file was deleted.

Loading