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
13f833a9
Commit
13f833a9
authored
5 years ago
by
Bert Palm
🎇
Browse files
Options
Downloads
Patches
Plain Diff
rework set again
parent
c3921b10
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!2
Develop
,
!1
complete rework
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
dios/dios.py
+70
-11
70 additions, 11 deletions
dios/dios.py
test/run_dios.py
+3
-0
3 additions, 0 deletions
test/run_dios.py
with
73 additions
and
11 deletions
dios/dios.py
+
70
−
11
View file @
13f833a9
...
...
@@ -8,7 +8,8 @@ import operator as op
from
functools
import
wraps
from
collections
import
OrderedDict
from
pandas._libs.lib
import
to_object_array
from
pandas._libs.lib
import
to_object_array
,
is_bool_array
from
pandas.core.common
import
is_bool_indexer
from
pandas.core.dtypes.common
import
(
is_list_like
,
is_nested_list_like
,
...
...
@@ -20,6 +21,19 @@ from pandas.core.dtypes.common import (
from
pandas.core.dtypes.common
import
is_iterator
as
_is_iterator
def
is_dios_like
(
obj
):
return
isinstance
(
obj
,
DictOfSeries
)
def
is_pandas_like
(
obj
):
"""
We consider ourselfs (dios) as pandas-like
"""
return
is_series_like
(
obj
)
or
is_dataframe_like
(
obj
)
or
is_dios_like
(
obj
)
def
is_series_like
(
obj
):
return
isinstance
(
obj
,
pd
.
Series
)
def
is_dataframe_like
(
obj
):
return
isinstance
(
obj
,
pd
.
DataFrame
)
def
is_iterator
(
obj
):
"""
This is only a dummy wrapper, to warn that the docu of this isnt
'
t right.
Unlike the example says,
...
...
@@ -226,26 +240,70 @@ class DictOfSeries:
if
is_iterator
(
key
):
key
=
list
(
key
)
keys
=
None
indexers
=
None
ki
=
dict
()
# determine action by keys
if
isinstance
(
key
,
str
):
# special case: insert a fresh new key
if
key
not
in
self
.
columns
:
self
.
_setitem_new
(
key
,
value
)
return
else
:
self
.
_setitem
(
key
,
valu
e
)
return
ki
[
key
]
=
slice
(
Non
e
)
keys
=
[
key
]
elif
isinstance
(
key
,
slice
):
keys
=
self
.
columns
kslicer
=
key
indexers
=
[
key
]
# list, np.arrays, ... of list, np.arrays..
elif
is_nested_list_like
(
key
):
keys
=
self
.
columns
indexers
=
[]
# we only allow nested lists with bool entries
for
i
in
range
(
len
(
key
)):
arr
=
np
.
array
(
i
)
if
not
is_bool_array
(
arr
):
raise
ValueError
(
"
Must pass nested-list-like with boolean values only
"
)
indexers
.
append
(
arr
)
# ser, df, dios
elif
is_pandas_like
(
key
):
if
is_series_like
(
key
):
keys
=
key
.
to_list
()
elif
is_dataframe_like
(
key
):
keys
=
key
.
columns
.
to_list
()
indexers
=
key
.
values
testbool
=
True
elif
is_dios_like
(
key
):
keys
=
key
.
columns
indexers
=
list
(
key
.
values
)
# list, np.array, np.ndarray, ...
elif
is_list_like
(
key
):
arr
=
np
.
array
(
key
)
if
is_bool_array
(
arr
):
keys
=
self
.
columns
indexers
=
[
arr
]
else
:
keys
=
key
elif
is_list_like
(
key
)
and
not
is_nested_list_like
(
key
):
self
.
_check_keys
(
key
)
keys
=
key
kslicer
=
None
else
:
raise
KeyError
(
f
"
{
key
}
"
)
if
length
!=
len
(
keys
):
raise
ValueError
(
f
"
Length mismatch for nested list: expected
{
len
(
keys
)
}
, got
{
length
}
"
)
if
not
indexers
:
indexers
=
[
slice
(
None
)]
if
len
(
indexers
)
==
1
:
indexers
=
indexers
*
len
(
keys
)
assert
len
(
indexers
)
==
len
(
keys
)
# now we have a indexer for every series
# determine action by value
if
isinstance
(
value
,
DictOfSeries
):
...
...
@@ -282,9 +340,10 @@ class DictOfSeries:
if
isinstance
(
val
,
pd
.
Series
):
val
=
cast_to_itype
(
val
,
self
.
_itype
,
policy
=
self
.
_policy
)
left
=
self
.
_data
[
key
][
sl
]
l
,
r
=
left
.
align
(
val
,
join
=
'
inner
'
)
if
not
r
.
empty
:
left
.
loc
[
r
.
index
]
=
r
.
copy
(
deep
=
True
)
idx
=
left
.
index
.
intersection
(
val
.
index
)
# l, r = left.align(val, join='inner')
if
not
idx
.
empty
:
left
.
loc
[
idx
]
=
val
.
loc
[
idx
].
copy
()
return
item
=
self
.
_data
[
key
]
...
...
This diff is collapsed.
Click to expand it.
test/run_dios.py
+
3
−
0
View file @
13f833a9
...
...
@@ -5,6 +5,9 @@ import numpy as np
if
__name__
==
'
__main__
'
:
# dios_options[Options.mixed_itype_policy] = 'error'
df
=
pd
.
DataFrame
([
1
,
24
,
5
,
456
,
45
],
index
=
pd
.
date_range
(
periods
=
5
,
freq
=
'
1d
'
,
start
=
'
2000-01-01
'
))
df
[[
True
,
False
]]
dios
=
DictOfSeries
(
data
=
[
234.54
,
5
,
5
,
4
,
np
.
nan
,
5
,
4
,
5
])
dios
=
abs
(
-
dios
)
...
...
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