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
ec057bcf
Commit
ec057bcf
authored
5 years ago
by
Bert Palm
🎇
Browse files
Options
Downloads
Patches
Plain Diff
aloc __getitem__
parent
83c27834
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
+13
-14
13 additions, 14 deletions
dios/dios.py
dios/locator.py
+52
-4
52 additions, 4 deletions
dios/locator.py
dios/options.py
+1
-1
1 addition, 1 deletion
dios/options.py
with
66 additions
and
19 deletions
dios/dios.py
+
13
−
14
View file @
ec057bcf
...
...
@@ -72,7 +72,7 @@ class DictOfSeries:
def
__init__
(
self
,
data
=
None
,
columns
=
None
,
itype
=
MixedItype
,
downcast_policy
=
'
save
'
):
self
.
_data
=
pd
.
Series
()
self
.
_data
=
pd
.
Series
(
dtype
=
'
O
'
)
# We need to keep track of the index-type (itype) of every new Series.
# If the itypes differ between different series, slicing will almost always fail
# (eg. a datetime-like slice cannot work on a numeric index and vice versa).
...
...
@@ -189,7 +189,7 @@ class DictOfSeries:
new
=
self
.
_getitem_bool_listlike
(
key
)
else
:
# work on columns
new
=
self
.
copy_empty
()
new
=
self
.
copy_empty
(
columns
=
False
)
new
.
_data
=
self
.
_data
[
key
]
return
new
...
...
@@ -198,7 +198,7 @@ class DictOfSeries:
if
key
==
slice
(
None
):
return
self
.
copy
()
new
=
self
.
copy_empty
()
new
=
self
.
copy_empty
(
columns
=
False
)
for
k
in
self
.
columns
:
new
.
_data
.
at
[
k
]
=
self
.
_data
.
at
[
k
][
key
]
return
new
...
...
@@ -210,7 +210,7 @@ class DictOfSeries:
if
not
is_bool_indexer
(
key
[
k
]):
raise
ValueError
(
"
Must pass DictOfSeries with boolean values only
"
)
new
=
self
.
copy_empty
()
new
=
self
.
copy_empty
(
columns
=
True
)
for
k
in
keys
:
ser
=
self
.
_data
.
at
[
k
]
boolser
=
key
[
k
]
...
...
@@ -220,7 +220,7 @@ class DictOfSeries:
return
new
def
_getitem_bool_listlike
(
self
,
key
):
new
=
self
.
copy_empty
()
new
=
self
.
copy_empty
(
columns
=
False
)
for
k
in
self
.
columns
:
new
.
_data
.
at
[
k
]
=
self
.
_data
.
at
[
k
].
loc
[
key
]
return
new
...
...
@@ -348,7 +348,7 @@ class DictOfSeries:
return
self
.
copy
(
deep
=
True
)
def
copy
(
self
,
deep
=
True
):
new
=
self
.
copy_empty
(
)
new
=
DictOfSeries
(
itype
=
self
.
itype
)
# We use `_data` here, because all checks are already done.
# So this should be much faster, especially, because we use the underlying dict for
# getting and setting the values, instead of ``__setitem__`` and ``__getitem__``.
...
...
@@ -356,10 +356,8 @@ class DictOfSeries:
new
.
_data
.
at
[
i
]
=
self
.
_data
.
at
[
i
].
copy
(
deep
=
deep
)
return
new
def
copy_empty
(
self
):
new
=
DictOfSeries
()
new
.
_itype
=
self
.
itype
return
new
def
copy_empty
(
self
,
columns
=
True
):
return
DictOfSeries
(
columns
=
self
.
columns
if
columns
is
True
else
None
,
itype
=
self
.
itype
)
def
to_df
(
self
):
return
self
.
_data
.
apply
(
lambda
s
:
s
).
transpose
()
...
...
@@ -399,7 +397,7 @@ class DictOfSeries:
pass
if
need_dios
:
dios
=
self
.
copy_empty
()
dios
=
self
.
copy_empty
(
columns
=
False
)
for
i
,
c
in
enumerate
(
self
.
columns
):
dios
[
c
]
=
pd
.
Series
(
new
[
i
])
new
=
dios
...
...
@@ -408,7 +406,7 @@ class DictOfSeries:
return
new
def
_op1
(
self
,
op
):
new
=
self
.
copy_empty
()
new
=
self
.
copy_empty
(
columns
=
False
)
try
:
for
k
in
self
.
columns
:
new
[
k
]
=
op
(
self
[
k
])
...
...
@@ -448,7 +446,7 @@ class DictOfSeries:
else
:
raise
NotImplementedError
new
=
self
if
inplace
else
self
.
copy_empty
()
new
=
self
if
inplace
else
self
.
copy_empty
(
columns
=
True
)
try
:
for
k
,
val
in
gen
():
new
[
k
]
=
val
...
...
@@ -479,7 +477,8 @@ class DictOfSeries:
def
pprint
(
dios
,
max_rows
=
10
,
max_cols
=
2
,
delim
=
'
'
):
if
dios
.
empty
:
return
"
Empty DictionaryOfSeries
"
return
f
"
Empty DictionaryOfSeries
\n
"
\
f
"
Columns:
{
dios
.
columns
.
to_list
()
}
"
sstr
=
[]
cols
=
list
(
dios
.
columns
)
...
...
This diff is collapsed.
Click to expand it.
dios/locator.py
+
52
−
4
View file @
ec057bcf
...
...
@@ -49,7 +49,7 @@ class _LocIndexer(_Indexer):
if
is_hashable
(
rowkey
):
new
=
data
else
:
new
=
self
.
_dios
.
copy_empty
()
new
=
self
.
_dios
.
copy_empty
(
columns
=
False
)
new
.
_data
=
data
return
new
...
...
@@ -100,7 +100,7 @@ class _iLocIndexer(_Indexer):
if
is_integer
(
rowkey
):
new
=
data
else
:
new
=
self
.
_dios
.
copy_empty
()
new
=
self
.
_dios
.
copy_empty
(
columns
=
False
)
new
.
_data
=
data
return
new
...
...
@@ -139,9 +139,57 @@ class _aLocIndexer(_Indexer):
raise
NotImplementedError
def
__getitem__
(
self
,
key
):
# todo
raise
NotImplementedError
if
is_dios_like
(
key
):
raise
NotImplementedError
else
:
rowkey
,
colkey
=
self
.
_unpack_key
(
key
)
# filter column key
# make column-slice from scalar
if
is_hashable
(
colkey
):
colkey
=
[
colkey
]
if
colkey
in
self
.
_dios
.
columns
else
[]
# pd.Series(a=True, b=False, x=True), columns:[a,b,c,d,] -> [a,]
elif
is_bool_series
(
colkey
):
colkey
=
self
.
_dios
.
columns
.
intersection
(
colkey
[
colkey
].
index
).
to_list
()
# filter only existing columns from list
elif
is_list_like_not_nested
(
colkey
):
colkey
=
[
c
for
c
in
self
.
_dios
.
columns
if
c
in
colkey
]
else
:
colkey
=
self
.
_data
.
loc
[
colkey
].
index
.
to_list
()
# filter row key
# make row-slice from scalar
if
is_hashable
(
rowkey
):
rowkey
=
[
slice
(
rowkey
,
rowkey
)]
*
len
(
colkey
)
# pd.Series(1=True, 4=False, 12=True)
# align every series, in columns
elif
is_bool_series
(
rowkey
):
rowkey
=
rowkey
[
rowkey
]
# kill False
rkeys
=
[]
for
c
in
colkey
:
rkeys
+=
[
self
.
_data
.
at
[
c
].
index
.
intersection
(
rowkey
.
index
)]
rowkey
=
rkeys
# filter only existing rows from list
elif
is_list_like_not_nested
(
rowkey
):
rkeys
=
[]
for
c
in
colkey
:
rkeys
+=
[
self
.
_data
.
at
[
c
].
index
.
intersection
(
rowkey
)]
rowkey
=
rkeys
else
:
rowkey
=
[
rowkey
]
*
len
(
colkey
)
new
=
self
.
_dios
.
copy_empty
(
columns
=
False
)
for
i
,
c
in
enumerate
(
colkey
):
new
.
_data
.
at
[
c
]
=
self
.
_dios
.
loc
[
rowkey
[
i
],
c
]
return
new
# #############################################################################
...
...
This diff is collapsed.
Click to expand it.
dios/options.py
+
1
−
1
View file @
ec057bcf
...
...
@@ -81,7 +81,7 @@ dios_options = {
def
align_dioslikes
(
self
,
other
,
nan
=
np
.
nan
,
policy
=
None
):
new
=
self
.
copy_empty
()
new
=
self
.
copy_empty
(
columns
=
False
)
for
k
in
self
.
columns
:
left
=
self
.
at
[
k
]
if
k
not
in
other
:
...
...
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