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
bcdcaeef
Commit
bcdcaeef
authored
5 years ago
by
Bert Palm
🎇
Browse files
Options
Downloads
Patches
Plain Diff
set get done
parent
058bded9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!2
Develop
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
df_vs_dios.ods
+0
-0
0 additions, 0 deletions
df_vs_dios.ods
dios/dios.py
+12
-42
12 additions, 42 deletions
dios/dios.py
with
12 additions
and
42 deletions
df_vs_dios.ods
+
0
−
0
View file @
bcdcaeef
No preview for this file type
This diff is collapsed.
Click to expand it.
dios/dios.py
+
12
−
42
View file @
bcdcaeef
...
...
@@ -49,16 +49,6 @@ def is_iterator(obj):
return
_is_iterator
(
obj
)
def
align
(
s1
,
s2
,
method
=
'
dropna
'
):
if
method
==
'
keepna
'
:
s
=
s1
.
reindex_like
(
s2
)
elif
method
==
'
dropna
'
:
s
=
s1
.
reindex_like
(
s2
).
dropna
()
else
:
raise
ValueError
(
method
)
return
s
class
DictOfSeries
:
"""
DictionaryOfSeries is a collection of pd.Series
'
s which aim to be as close as possible similar to
...
...
@@ -176,33 +166,13 @@ class DictOfSeries:
Notes:
- [1] If ``iterable`` contains any(!) label that does not exist, a KeyError is raised.
"""
if
is_bool_indexer
(
key
):
if
not
is_series_like
(
key
):
raise
ValueError
(
"
Only boolean series are allowed as boolean indexer.
"
)
new
=
self
.
copy_empty
()
for
c
in
self
.
columns
:
new
.
_data
[
c
]
=
align
(
self
.
_data
[
c
],
key
,
method
=
'
dropna
'
)
elif
is_series_like
(
key
):
raise
ValueError
(
"
Only series with boolean values are allowed as indexer
"
)
elif
isinstance
(
key
,
slice
):
new
=
self
.
copy_empty
()
for
c
in
self
.
_data
.
index
:
new
.
_data
[
c
]
=
self
.
_data
[
c
][
key
]
elif
isinstance
(
key
,
self
.
__class__
):
new
=
self
.
copy_empty
()
cols
=
self
.
columns
.
intersection
(
key
.
columns
)
for
c
in
cols
:
new
.
_data
[
c
]
=
align
(
key
.
_data
[
c
],
self
.
_data
[
c
])
elif
is_hashable
(
key
):
if
is_hashable
(
key
):
new
=
self
.
_data
[
key
]
else
:
new
=
self
.
copy
()
new
.
_data
=
self
.
_data
[
key
]
keys
,
ixs
,
doalign
=
self
.
_unpack_key
(
key
)
new
=
self
.
copy_empty
()
for
i
,
k
in
enumerate
(
keys
):
new
.
_data
.
loc
[
k
]
=
self
.
_data
[
k
][
i
]
return
new
def
__setitem__
(
self
,
key
,
value
):
...
...
@@ -233,20 +203,20 @@ class DictOfSeries:
assert
len
(
keys
)
==
len
(
ixs
)
gen
=
self
.
_unpack_value
(
keys
,
ixs
,
value
)
for
tup
in
gen
:
self
.
_set_item
(
*
tup
)
self
.
_set_item
(
*
tup
,
doalign
=
doalign
)
def
_set_item
(
self
,
key
,
ix
,
val
):
def
_set_item
(
self
,
key
,
ix
,
val
,
doalign
=
False
):
"
Set a value (scalar or list or series)
"
ser
=
self
.
_data
[
key
]
if
is_series_like
(
val
)
:
if
doalign
:
left
=
ser
[
ix
]
index
=
left
.
index
.
intersection
(
val
.
index
)
if
not
index
.
empty
:
left
.
loc
[
index
]
=
val
.
loc
[
index
].
copy
()
ser
.
loc
[
index
]
=
val
.
loc
[
index
].
copy
()
else
:
ser
[
ix
]
=
val
def
_insert
(
self
,
key
,
val
):
def
_insert
(
self
,
col
,
val
):
"""
Insert a fresh new value into self
"""
if
isinstance
(
val
,
DictOfSeries
):
val
=
val
.
squeeze
()
...
...
@@ -257,7 +227,7 @@ class DictOfSeries:
raise
ValueError
(
f
"
Only pd.Series can be inserted directly, given type
{
type
(
val
)
}
"
)
val
=
cast_to_itype
(
val
,
self
.
_itype
,
policy
=
self
.
_policy
)
self
.
_data
.
loc
[
key
]
=
val
.
copy
(
deep
=
True
)
self
.
_data
.
loc
[
col
]
=
val
.
copy
(
deep
=
True
)
def
_unpack_value
(
self
,
keys
,
ixs
,
val
):
"""
Return a generator that yield (key, indexer, value) for all keys
"""
...
...
@@ -297,7 +267,7 @@ class DictOfSeries:
keys
=
self
.
columns
.
intersection
(
key
.
columns
).
to_list
()
indexer
,
doalign
=
key
[
keys
].
to_list
(),
True
elif
is_list_like
(
key
)
and
not
is_nested_list_like
(
key
):
# policy is fix here. we only want to allow known keys or less; empty list is ok
# policy is fix
ed
here. we only want to allow known keys or less; empty list is ok
keys
=
check_keys_by_policy
(
key
,
self
.
columns
,
Opts
.
none_up2_all
)
indexer
=
[
slice
(
None
)]
*
len
(
keys
)
else
:
...
...
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