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

removed_type_system #535

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
32 changes: 22 additions & 10 deletions discretisedfield/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import ubermagutil.typesystem as ts
import ubermagutil.units as uu


@ts.typesystem(
dim=ts.Scalar(expected_type=int, positive=True, const=True),
n=ts.Scalar(expected_type=int, positive=True, const=True),
)
# @ts.typesystem(
# dim=ts.Scalar(expected_type=int, positive=True, const=True),
# n=ts.Scalar(expected_type=int, positive=True, const=True),
# )
class Line:
"""Line class.

Expand Down Expand Up @@ -99,13 +98,18 @@
raise ValueError(msg)

# Set the dimension (const descriptor).
if isinstance(values[0], numbers.Complex):
self.dim = 1
else:
self.dim = len(values[0])
dim = 1 if isinstance(values[0], numbers.Complex) else len(values[0])

if not isinstance(dim, int) or dim <= 0:
raise ValueError(f"dim must be a positive integer, got {dim}.")

Check warning on line 104 in discretisedfield/line.py

View check run for this annotation

Codecov / codecov/patch

discretisedfield/line.py#L104

Added line #L104 was not covered by tests

# Set the number of values (const descriptor).
self.n = len(points)
n = len(points)
if not isinstance(n, int) or n <= 0:
raise ValueError(f"n must be a positive integer, got {n}.")

Check warning on line 109 in discretisedfield/line.py

View check run for this annotation

Codecov / codecov/patch

discretisedfield/line.py#L109

Added line #L109 was not covered by tests

self._dim = dim
self._n = n

points = np.array(points)
values = np.array(values).reshape((points.shape[0], -1))
Expand All @@ -121,6 +125,14 @@
self._point_columns = list(point_columns)
self._value_columns = list(value_columns)

@property
def dim(self):
return self._dim

@property
def n(self):
return self._n

@property
def point_columns(self):
"""The names of point columns.
Expand Down
Loading