Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
dios
Manage
Activity
Members
Labels
Plan
Issues
11
Issue boards
Milestones
Wiki
Jira
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
RDM
dios
Commits
9b8414df
Commit
9b8414df
authored
5 years ago
by
Bert Palm
🎇
Browse files
Options
Downloads
Patches
Plain Diff
added reraise
parent
b193c4ce
No related branches found
No related tags found
2 merge requests
!2
Develop
,
!1
complete rework
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
dios/dios.py
+42
-15
42 additions, 15 deletions
dios/dios.py
dios/lib.py
+9
-0
9 additions, 0 deletions
dios/lib.py
test/run_dios.py
+3
-0
3 additions, 0 deletions
test/run_dios.py
test/test_dios.py
+25
-0
25 additions, 0 deletions
test/test_dios.py
with
79 additions
and
15 deletions
dios/dios.py
+
42
−
15
View file @
9b8414df
from
dios.lib
import
*
from
dios.options
import
*
import
pandas
as
pd
import
numpy
as
np
import
operator
as
op
from
collections
import
OrderedDict
...
...
@@ -56,7 +57,7 @@ class DictOfSeries:
"""
def
__init__
(
self
,
data
=
None
,
itype
=
None
,
columns
=
None
,
downcast_policy
=
'
lossless
'
):
def
__init__
(
self
,
data
=
None
,
columns
=
None
,
itype
=
None
,
downcast_policy
=
'
lossless
'
):
self
.
_data
=
OrderedDict
()
...
...
@@ -67,7 +68,8 @@ class DictOfSeries:
# May data was given, so we firstly set itype to MixedItype, then insert all data,
# and check/cast the itype afterwards, otherwise __setitem_new() will set the itype,
# which may prevent inserting series with other (higher) itypes.
self
.
_itype
=
MixedItype
with
reraise
(
"
param itype:
"
):
self
.
_itype
=
get_itype
(
itype
)
policies
=
[
'
force
'
,
'
lossless
'
,
'
never
'
]
if
downcast_policy
not
in
policies
:
...
...
@@ -400,18 +402,26 @@ class DictOfSeries:
pd
.
set_option
(
'
display.max_rows
'
,
pd_max_rows
)
return
s
def
__bool__
(
self
):
raise
ValueError
(
"
The truth value of a DictionaryOfSeries is ambiguous. Use a.empty, a.any() or a.all().
"
)
#
def __bool__(self):
#
raise ValueError("The truth value of a DictionaryOfSeries is ambiguous. Use a.empty, a.any() or a.all().")
@property
def
empty
(
self
):
return
all
(
self
.
_data
[
c
].
empty
for
c
in
self
.
_data
)
def
all
(
self
):
return
all
(
all
(
self
.
_data
[
c
])
for
c
in
self
.
_data
)
return
pd
.
Series
([
all
(
self
.
_data
[
c
])
for
c
in
self
.
_data
]
)
def
any
(
self
):
return
any
(
any
(
self
.
_data
[
c
])
for
c
in
self
.
_data
)
return
pd
.
Series
([
any
(
self
.
_data
[
c
])
for
c
in
self
.
_data
])
def
aaall
(
self
):
"""
absolute all all
"""
return
self
.
all
().
all
()
def
aaany
(
self
):
"""
absolute any any
"""
return
self
.
any
().
any
()
def
__len__
(
self
):
return
len
(
self
.
_data
)
...
...
@@ -425,6 +435,9 @@ class DictOfSeries:
def
__iter__
(
self
):
yield
from
self
.
_data
# def __array__(self):
# return [False, True]
def
__delitem__
(
self
,
key
):
del
self
.
_data
[
key
]
...
...
@@ -466,15 +479,9 @@ class DictOfSeries:
new
[
k
]
=
op
(
self
[
k
],
other
)
return
new
def
__neg__
(
self
):
return
self
.
__op1__
(
op
.
neg
)
def
__invert__
(
self
):
return
self
.
__op1__
(
op
.
inv
)
def
__abs__
(
self
):
return
self
.
__op1__
(
op
.
abs
)
# ----------------------------------
# comparators
# ----------------------------------
def
__lt__
(
self
,
other
):
return
self
.
__op2__
(
other
,
op
.
lt
)
...
...
@@ -493,6 +500,18 @@ class DictOfSeries:
def
__gt__
(
self
,
other
):
return
self
.
__op2__
(
other
,
op
.
gt
)
# ----------------------------------
# arithmetical
# ----------------------------------
def
__neg__
(
self
):
# -dios
return
self
.
__op1__
(
op
.
neg
)
def
__abs__
(
self
):
# abs(dios)
return
self
.
__op1__
(
op
.
abs
)
def
__add__
(
self
,
other
):
return
self
.
__op2__
(
other
,
op
.
add
)
...
...
@@ -514,6 +533,14 @@ class DictOfSeries:
def
__pow__
(
self
,
other
):
return
self
.
__op2__
(
other
,
op
.
pow
)
# ----------------------------------
# bool stuff
# ----------------------------------
def
__invert__
(
self
):
# ~dios
return
self
.
__op1__
(
op
.
inv
)
def
__and__
(
self
,
other
):
return
self
.
__op2__
(
other
,
op
.
and_
)
...
...
This diff is collapsed.
Click to expand it.
dios/lib.py
+
9
−
0
View file @
9b8414df
...
...
@@ -3,6 +3,15 @@ from dios.options import *
import
pandas
as
pd
import
warnings
import
contextlib
@contextlib.contextmanager
def
reraise
(
prefix
=
""
,
postfix
=
""
):
try
:
yield
except
Exception
as
e
:
raise
type
(
e
)(
prefix
+
str
(
e
)
+
postfix
)
from
e
def
_get_storage_class_values
(
cls
):
...
...
This diff is collapsed.
Click to expand it.
test/run_dios.py
+
3
−
0
View file @
9b8414df
...
...
@@ -6,6 +6,9 @@ if __name__ == '__main__':
# dios_options[Options.mixed_itype_policy] = 'error'
dios
=
DictOfSeries
(
data
=
[
234.54
,
5
,
5
,
4
,
np
.
nan
,
5
,
4
,
5
])
print
(
all
(
dios
==
dios
))
dtser
=
pd
.
Series
([
2
,
4
,
4123
,
122
,
4
],
index
=
pd
.
date_range
(
freq
=
'
1d
'
,
periods
=
5
,
start
=
'
2000-01-01
'
))
dios
[
'
b
'
]
=
dtser
dios2
=
dios
.
copy
()
...
...
This diff is collapsed.
Click to expand it.
test/test_dios.py
+
25
−
0
View file @
9b8414df
...
...
@@ -56,3 +56,28 @@ def test_copy_copy_empty__copy__(dictofseries):
dios
[
i
][
0
]
=
999999
assert
dios
[
i
][
0
]
==
shallow
[
i
][
0
]
assert
dios
[
i
][
0
]
!=
deep
[
i
][
0
]
def
test__mul__
(
dictofseries
):
a
=
dictofseries
.
copy
()
for
i
in
[
1
,
2
,
50
,
33.3
,
0.1
,
0
]:
b
=
a
*
i
for
c
in
b
:
exp
=
a
[
c
]
*
i
assert
np
.
all
(
b
[
c
]
==
exp
)
assert
b
[
c
]
is
not
exp
def
test__eq__
(
dictofseries
):
a
=
dictofseries
.
copy
()
b
=
dictofseries
.
copy
()
assert
a
is
not
b
assert
(
a
==
b
).
aaall
()
x
=
b
[
'
c0
'
]
x
.
iloc
[
5
]
=
5
b
[
'
c0
'
]
=
x
assert
(
a
!=
b
).
aaany
()
# assert False
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