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
83c27834
Commit
83c27834
authored
5 years ago
by
Bert Palm
🎇
Browse files
Options
Downloads
Patches
Plain Diff
bugfixes
parent
38a9b89f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
dios/dios.py
+15
-4
15 additions, 4 deletions
dios/dios.py
dios/lib.py
+0
-9
0 additions, 9 deletions
dios/lib.py
dios/locator.py
+24
-39
24 additions, 39 deletions
dios/locator.py
with
39 additions
and
52 deletions
dios/dios.py
+
15
−
4
View file @
83c27834
...
...
@@ -241,10 +241,21 @@ class DictOfSeries:
data
=
self
.
__getitem__
(
key
)
assert
isinstance
(
data
,
self
.
__class__
),
f
"
getitem returned data of type
{
type
(
data
)
}
"
for
k
in
data
.
columns
:
s
=
data
.
_data
.
at
[
k
]
s
[:]
=
value
self
.
_data
.
at
[
k
].
loc
[
s
.
index
]
=
s
if
is_dios_like
(
value
):
self
.
_setitem_dios
(
data
,
value
)
else
:
for
k
in
data
.
columns
:
s
=
data
.
_data
.
at
[
k
]
s
[:]
=
value
self
.
_data
.
at
[
k
].
loc
[
s
.
index
]
=
s
def
_setitem_dios
(
self
,
data
,
value
):
keys
=
self
.
columns
.
intersection
(
data
.
columns
)
for
k
in
keys
:
l
=
self
.
_data
.
at
[
k
]
r
=
value
[
k
]
idx
=
l
.
index
.
intersection
(
r
.
index
)
l
[
idx
]
=
r
[
idx
]
@property
def
loc
(
self
):
...
...
This diff is collapsed.
Click to expand it.
dios/lib.py
+
0
−
9
View file @
83c27834
...
...
@@ -5,15 +5,6 @@ import contextlib
import
operator
as
op
# @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
):
return
[
getattr
(
cls
,
c
)
for
c
in
cls
.
__dict__
if
not
c
.
startswith
(
"
_
"
)]
...
...
This diff is collapsed.
Click to expand it.
dios/locator.py
+
24
−
39
View file @
83c27834
...
...
@@ -16,10 +16,8 @@ class _Indexer:
else
:
rowkey
,
colkey
=
key
,
slice
(
None
)
if
isinstance
(
rowkey
,
tuple
):
if
isinstance
(
rowkey
,
tuple
)
or
isinstance
(
colkey
,
tuple
):
raise
KeyError
(
f
"
{
key
}
. tuples are not allowed.
"
)
if
is_dios_like
(
rowkey
)
or
is_dios_like
(
colkey
):
raise
ValueError
(
"
Cannot index with multidimensional key
"
)
return
rowkey
,
colkey
...
...
@@ -35,7 +33,10 @@ class _LocIndexer(_Indexer):
def
__getitem__
(
self
,
key
):
rowkey
,
colkey
=
self
.
_unpack_key
(
key
)
data
=
self
.
_data
.
loc
[
colkey
]
if
is_dios_like
(
rowkey
)
or
is_dios_like
(
colkey
):
raise
ValueError
(
"
Cannot index with multidimensional key
"
)
data
=
self
.
_data
.
loc
[
colkey
].
copy
()
# .loc[any, scalar]
if
is_hashable
(
colkey
):
...
...
@@ -56,6 +57,8 @@ class _LocIndexer(_Indexer):
def
__setitem__
(
self
,
key
,
value
):
rowkey
,
colkey
=
self
.
_unpack_key
(
key
)
if
is_dios_like
(
rowkey
)
or
is_dios_like
(
colkey
):
raise
ValueError
(
"
Cannot index with multidimensional key
"
)
# .loc[any, scalar]
if
is_hashable
(
colkey
):
...
...
@@ -81,7 +84,10 @@ class _iLocIndexer(_Indexer):
def
__getitem__
(
self
,
key
):
rowkey
,
colkey
=
self
.
_unpack_key
(
key
)
data
=
self
.
_data
.
iloc
[
colkey
]
if
is_dios_like
(
rowkey
)
or
is_dios_like
(
colkey
):
raise
ValueError
(
"
Cannot index with multidimensional key
"
)
data
=
self
.
_data
.
iloc
[
colkey
].
copy
()
# .iloc[any, scalar]
if
is_integer
(
colkey
):
...
...
@@ -101,6 +107,9 @@ class _iLocIndexer(_Indexer):
def
__setitem__
(
self
,
key
,
value
):
rowkey
,
colkey
=
self
.
_unpack_key
(
key
)
if
is_dios_like
(
rowkey
)
or
is_dios_like
(
colkey
):
raise
ValueError
(
"
Cannot index with multidimensional key
"
)
# .iloc[any, scalar]
if
is_integer
(
colkey
):
...
...
@@ -116,17 +125,22 @@ class _iLocIndexer(_Indexer):
class
_aLocIndexer
(
_Indexer
):
"""
align Indexer
automatically align (alignable) values on all possible axis,
and handle indexing with non-existent or missing keys grateful
"""
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
().
__init__
(
*
args
,
**
kwargs
)
def
__setitem__
(
self
,
key
,
value
):
# fallback to loc
if
not
is_dios_like
(
value
)
and
not
is_nested_list_like
(
value
):
self
.
_dios
.
loc
[
key
]
=
value
# todo
raise
NotImplementedError
def
__getitem__
(
self
,
item
):
return
item
def
__getitem__
(
self
,
key
):
# todo
raise
NotImplementedError
# #############################################################################
...
...
@@ -182,32 +196,3 @@ class _iAtIndexer(_Indexer):
# #############################################################################
def
_unpack_value
(
keys
,
ix
,
val
):
"""
Return a generator that yield (column key, corresponding value, value-align(bool) )
for all columns.
This is analogous to DictOfSeries._unpack_value, but with some modifications.
"""
# prepare value
val
=
list
(
val
)
if
is_iterator
(
val
)
else
val
val
=
val
.
squeeze
(
axis
=
1
)
if
is_dios_like
(
val
)
else
val
dioslike
,
nlistlike
=
is_dios_like
(
val
),
is_nested_list_like
(
val
)
# check value
if
nlistlike
and
len
(
val
)
!=
len
(
keys
):
raise
ValueError
(
f
"
could not broadcast input array with length
{
len
(
val
)
}
"
f
"
into dios of length
{
len
(
keys
)
}
"
)
if
dioslike
:
keys
=
val
.
columns
.
intersection
(
keys
)
for
i
,
k
in
enumerate
(
keys
):
if
dioslike
:
yield
k
,
ix
,
val
[
k
]
elif
nlistlike
:
yield
k
,
ix
,
val
[
i
]
else
:
yield
k
,
ix
,
val
def
maby_set_series_name
(
maybe_ser
,
name
):
if
isinstance
(
maybe_ser
,
pd
.
Series
):
maybe_ser
.
name
=
name
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