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
8758025e
Commit
8758025e
authored
5 years ago
by
Bert Palm
🎇
Browse files
Options
Downloads
Patches
Plain Diff
wip
parent
b0c62ced
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!2
Develop
,
!1
complete rework
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
dios/dios.py
+72
-12
72 additions, 12 deletions
dios/dios.py
with
72 additions
and
12 deletions
dios/dios.py
+
72
−
12
View file @
8758025e
...
...
@@ -7,6 +7,7 @@ from collections import OrderedDict
from
itertools
import
islice
import
operator
as
op
import
functools
from
pandas.core.indexing
import
need_slice
# _listlike = (list, set)
...
...
@@ -44,20 +45,69 @@ def item_from_zerodim(key):
class
_LocIndexer
:
def
__init__
(
self
,
_data
):
self
.
_data
=
_data
def
__init__
(
self
,
_dios
):
self
.
_dios
=
_dios
# short handles
self
.
_data
=
_dios
.
_data
self
.
_check_keys
=
_dios
.
_check_keys
def
__getitem__
(
self
,
key
):
rkey
=
None
ckey
=
None
# unpack tuple
# if we have a tuple, we have rows and columns
# if not we have only rows
if
isinstance
(
key
,
tuple
):
rkey
,
ckey
,
*
fail
=
key
if
fail
:
raise
KeyError
(
"
To many indexers
"
)
# prepare ckey
if
is_iterator
(
ckey
):
ckey
=
list
(
ckey
)
# determine columns
if
isinstance
(
ckey
,
str
):
self
.
_check_keys
([
ckey
])
cols
=
[
ckey
]
elif
isinstance
(
ckey
,
slice
):
cols
=
self
.
_col_slice_to_col_list
(
ckey
)
elif
is_list_like
(
ckey
):
self
.
_check_keys
(
ckey
)
cols
=
ckey
else
:
raise
KeyError
(
f
"
Type
{
type
(
ckey
)
}
is not supported to select columns.
"
)
else
:
cols
=
list
(
self
.
_data
.
keys
())
rkey
=
key
# prepare rkey
rkey
=
item_from_zerodim
(
rkey
)
if
is_iterator
(
rkey
):
rkey
=
list
(
rkey
)
# determine rows, these are mandatory
# slice, bool, list-like, label
if
isinstance
(
rkey
,
slice
):
# todo: validate slice ?
return
self
.
_slice
(
cols
,
rkey
)
def
_slice
(
self
,
keys
,
sl
):
new
=
DictOfSeries
()
for
k
in
keys
:
new
[
k
]
=
self
.
_data
[
k
][
sl
]
return
new
def
_col_slice_to_col_list
(
self
,
rslice
):
"""
see here:
https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#indexing-slicing-with-labels
"""
keys
=
list
(
self
.
_data
.
keys
)
try
:
start
=
keys
.
index
(
rslice
.
start
)
if
rslice
.
start
is
not
None
else
None
stop
=
keys
.
index
(
rslice
.
stop
)
if
rslice
.
stop
is
not
None
else
None
except
ValueError
:
raise
KeyError
(
"
The slice start label or the slice stop label is not present in the columns.
"
)
if
not
is_number
(
rslice
):
raise
TypeError
(
"
The step parameter of the slice must be numeric.
"
)
return
keys
[
slice
(
start
,
stop
,
rslice
.
step
)]
class
DictOfSeries
:
...
...
@@ -103,7 +153,11 @@ class DictOfSeries:
If
'
iterable
'
contains any(!) label that does not exist
a KeyError is raised
"""
# prepare
key
=
item_from_zerodim
(
key
)
if
is_iterator
(
key
):
key
=
list
(
key
)
# todo: allow any hashable obj, except stuff that fail: None/np.nan
if
isinstance
(
key
,
str
):
...
...
@@ -146,6 +200,11 @@ class DictOfSeries:
dios[iterable]
"""
# prepare
key
=
item_from_zerodim
(
key
)
if
is_iterator
(
key
):
key
=
list
(
key
)
# determine action by keys
if
isinstance
(
key
,
str
):
if
key
not
in
self
.
columns
:
...
...
@@ -247,11 +306,9 @@ class DictOfSeries:
for
k
in
keys
:
self
.
_setitem
(
k
,
other
[
k
],
slicer
)
@property
def
loc
(
self
):
return
_LocIndexer
(
self
.
_data
)
return
_LocIndexer
(
self
)
def
__str__
(
self
):
return
self
.
__repr__
()
...
...
@@ -284,13 +341,13 @@ class DictOfSeries:
@property
def
empty
(
self
):
return
all
(
c
.
empty
for
c
in
self
.
_data
)
return
all
(
self
.
_data
[
c
]
.
empty
for
c
in
self
.
_data
)
def
all
(
self
):
return
all
(
all
(
c
)
for
c
in
self
.
_data
)
return
all
(
all
(
self
.
_data
[
c
]
)
for
c
in
self
.
_data
)
def
any
(
self
):
return
any
(
any
(
c
)
for
c
in
self
.
_data
)
return
any
(
any
(
self
.
_data
[
c
]
)
for
c
in
self
.
_data
)
def
__len__
(
self
):
return
len
(
self
.
_data
)
...
...
@@ -458,6 +515,9 @@ if __name__ == '__main__':
dios2
=
dios
.
copy
()
a
=
dios
.
loc
[
9
]
df
=
pd
.
DataFrame
([
1
,
24
,
5
,
456
,
45
],
index
=
pd
.
date_range
(
periods
=
5
,
freq
=
'
1d
'
,
start
=
'
2000-01-01
'
))
a
=
df
.
loc
[
"
2000-01-02
"
:]
print
(
a
)
exit
(
4
)
dios
.
columns
=
[
'
foo
'
,
'
bar
'
]
...
...
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