Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
firanka
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
public
firanka
Commits
662a47d3
Commit
662a47d3
authored
7 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
added DomainError
parent
67b3ee54
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
firanka/exceptions.py
+6
-1
6 additions, 1 deletion
firanka/exceptions.py
firanka/intervals.py
+21
-16
21 additions, 16 deletions
firanka/intervals.py
firanka/series/base.py
+2
-3
2 additions, 3 deletions
firanka/series/base.py
tests/test_series.py
+3
-3
3 additions, 3 deletions
tests/test_series.py
with
32 additions
and
23 deletions
firanka/exceptions.py
+
6
−
1
View file @
662a47d3
...
@@ -4,6 +4,7 @@ from __future__ import print_function, absolute_import, division
...
@@ -4,6 +4,7 @@ from __future__ import print_function, absolute_import, division
__all__
=
[
__all__
=
[
'
FirankaError
'
,
'
FirankaError
'
,
'
NotInDomainError
'
,
'
NotInDomainError
'
,
'
DomainError
'
,
]
]
...
@@ -13,7 +14,11 @@ class FirankaError(Exception):
...
@@ -13,7 +14,11 @@ class FirankaError(Exception):
"""
"""
class
NotInDomainError
(
FirankaError
,
ValueError
):
class
DomainError
(
FirankaError
):
"""
Has something to do with the domain :)
"""
class
NotInDomainError
(
DomainError
,
ValueError
):
"""
"""
Requested index is beyond this domain
Requested index is beyond this domain
"""
"""
This diff is collapsed.
Click to expand it.
firanka/intervals.py
+
21
−
16
View file @
662a47d3
...
@@ -117,27 +117,32 @@ class Interval(object):
...
@@ -117,27 +117,32 @@ class Interval(object):
self
.
start
,
self
.
stop
,
self
.
left_inc
,
self
.
right_inc
=
args
self
.
start
,
self
.
stop
,
self
.
left_inc
,
self
.
right_inc
=
args
def
_contains_point
(
self
,
x
):
if
x
==
self
.
start
:
return
self
.
left_inc
if
x
==
self
.
stop
:
return
self
.
right_inc
return
self
.
start
<
x
<
self
.
stop
@_pre_range
def
_contains_interval
(
self
,
x
):
if
((
x
.
start
==
self
.
start
)
and
(
x
.
left_inc
^
self
.
left_inc
))
\
or
((
x
.
stop
==
self
.
stop
)
and
(
x
.
right_inc
^
self
.
right_inc
)):
return
False
return
(
x
.
start
>=
self
.
start
)
and
(
x
.
stop
<=
self
.
stop
)
def
__contains__
(
self
,
x
):
def
__contains__
(
self
,
x
):
"""
"""
:type x: index or a Interval
:type x: index or a Interval
"""
"""
if
isinstance
(
x
,
six
.
string_types
):
if
isinstance
(
x
,
six
.
string_types
)
or
isinstance
(
x
,
Interval
):
x
=
Interval
(
x
)
return
self
.
_contains_interval
(
x
)
if
isinstance
(
x
,
Interval
):
if
((
x
.
start
==
self
.
start
)
and
(
x
.
left_inc
^
self
.
left_inc
))
\
or
((
x
.
stop
==
self
.
stop
)
and
(
x
.
right_inc
^
self
.
right_inc
)):
return
False
return
(
x
.
start
>=
self
.
start
)
and
(
x
.
stop
<=
self
.
stop
)
else
:
else
:
if
x
==
self
.
start
:
return
self
.
_contains_point
(
x
)
return
self
.
left_inc
if
x
==
self
.
stop
:
return
self
.
right_inc
return
self
.
start
<
x
<
self
.
stop
def
is_empty
(
self
):
def
is_empty
(
self
):
return
(
self
.
start
==
self
.
stop
)
and
not
(
return
(
self
.
start
==
self
.
stop
)
and
not
(
...
@@ -153,7 +158,7 @@ class Interval(object):
...
@@ -153,7 +158,7 @@ class Interval(object):
def
__getitem__
(
self
,
item
):
def
__getitem__
(
self
,
item
):
if
not
isinstance
(
item
,
slice
):
if
not
isinstance
(
item
,
slice
):
raise
Valu
eError
(
'
must be a slice
'
)
raise
Typ
eError
(
'
must be a slice
'
)
return
self
.
intersection
(
Interval
(
item
))
return
self
.
intersection
(
Interval
(
item
))
...
...
This diff is collapsed.
Click to expand it.
firanka/series/base.py
+
2
−
3
View file @
662a47d3
...
@@ -5,7 +5,7 @@ import inspect
...
@@ -5,7 +5,7 @@ import inspect
from
sortedcontainers
import
SortedList
from
sortedcontainers
import
SortedList
from
firanka.exceptions
import
NotInDomainError
from
firanka.exceptions
import
NotInDomainError
,
DomainError
from
firanka.intervals
import
Interval
,
EMPTY_SET
from
firanka.intervals
import
Interval
,
EMPTY_SET
...
@@ -127,8 +127,7 @@ class DiscreteSeries(Series):
...
@@ -127,8 +127,7 @@ class DiscreteSeries(Series):
if
len
(
data
)
>
0
:
if
len
(
data
)
>
0
:
if
self
.
domain
.
start
<
data
[
0
][
0
]:
if
self
.
domain
.
start
<
data
[
0
][
0
]:
raise
ValueError
(
raise
DomainError
(
'
some domain space is not covered by definition!
'
)
'
some domain space is not covered by definition!
'
)
def
apply
(
self
,
fun
):
def
apply
(
self
,
fun
):
assert
_has_arguments
(
fun
,
2
),
'
fun must have at least 2 arguments
'
assert
_has_arguments
(
fun
,
2
),
'
fun must have at least 2 arguments
'
...
...
This diff is collapsed.
Click to expand it.
tests/test_series.py
+
3
−
3
View file @
662a47d3
...
@@ -4,7 +4,7 @@ from __future__ import print_function, absolute_import, division
...
@@ -4,7 +4,7 @@ from __future__ import print_function, absolute_import, division
import
math
import
math
import
unittest
import
unittest
from
firanka.exceptions
import
NotInDomainError
from
firanka.exceptions
import
NotInDomainError
,
DomainError
from
firanka.intervals
import
Interval
from
firanka.intervals
import
Interval
from
firanka.series
import
DiscreteSeries
,
FunctionSeries
,
ModuloSeries
,
\
from
firanka.series
import
DiscreteSeries
,
FunctionSeries
,
ModuloSeries
,
\
LinearInterpolationSeries
,
Series
LinearInterpolationSeries
,
Series
...
@@ -27,7 +27,7 @@ class TestDiscreteSeries(unittest.TestCase):
...
@@ -27,7 +27,7 @@ class TestDiscreteSeries(unittest.TestCase):
a
.
join
(
b
,
lambda
i
,
x
,
y
:
x
+
y
)
a
.
join
(
b
,
lambda
i
,
x
,
y
:
x
+
y
)
def
test_uncov
(
self
):
def
test_uncov
(
self
):
self
.
assertRaises
(
Value
Error
,
self
.
assertRaises
(
Domain
Error
,
lambda
:
DiscreteSeries
([[
0
,
0
],
[
1
,
1
],
[
2
,
2
]],
lambda
:
DiscreteSeries
([[
0
,
0
],
[
1
,
1
],
[
2
,
2
]],
'
<-5;2>
'
))
'
<-5;2>
'
))
...
@@ -124,7 +124,7 @@ class TestDiscreteSeries(unittest.TestCase):
...
@@ -124,7 +124,7 @@ class TestDiscreteSeries(unittest.TestCase):
def
test_discretize
(
self
):
def
test_discretize
(
self
):
# note the invalid data for covering this domain
# note the invalid data for covering this domain
self
.
assertRaises
(
Value
Error
,
lambda
:
FunctionSeries
(
lambda
x
:
x
**
2
,
self
.
assertRaises
(
Domain
Error
,
lambda
:
FunctionSeries
(
lambda
x
:
x
**
2
,
'
<-10;10)
'
).
discretize
(
'
<-10;10)
'
).
discretize
(
[
0
,
1
,
2
,
3
,
4
,
5
],
'
(-1;6)
'
))
[
0
,
1
,
2
,
3
,
4
,
5
],
'
(-1;6)
'
))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment