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
0a689c3e
Commit
0a689c3e
authored
5 years ago
by
Bert Palm
🎇
Browse files
Options
Downloads
Patches
Plain Diff
implemented rudimentary __setattr__
parent
4acf0ea4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
dios/dios.py
+33
-6
33 additions, 6 deletions
dios/dios.py
with
33 additions
and
6 deletions
dios/dios.py
+
33
−
6
View file @
0a689c3e
...
...
@@ -4,6 +4,7 @@ import datetime as dt
from
collections
import
OrderedDict
from
itertools
import
islice
import
operator
as
op
import
functools
dios_options
=
dict
(
disp_max_rows
=
10
,
...
...
@@ -37,7 +38,7 @@ class DictOfSeries(OrderedDict):
if
isinstance
(
k
,
str
):
if
k
in
self
.
__keys
:
keygen
=
[
k
]
el
if
isinstance
(
value
,
(
pd
.
Series
,
DictOfSeries
))
:
el
se
:
self
.
__addnew
(
k
,
value
)
return
else
:
...
...
@@ -56,12 +57,17 @@ class DictOfSeries(OrderedDict):
if
isinstance
(
v
,
DictOfSeries
):
v
=
value
.
squeeze
()
if
v
is
value
:
# squeeze failed to squeeze
raise
ValueError
(
f
"
only DictOfSeries of length 1 can be assigned new
"
)
if
isinstance
(
v
,
list
):
v
=
pd
.
Series
(
v
)
if
isinstance
(
v
,
pd
.
Series
):
super
().
__setitem__
(
key
,
v
.
copy
(
deep
=
True
))
self
.
__keys
.
append
(
key
)
return
else
:
raise
ValueError
(
f
"
Only pd.Series and DictOfSeries (of length 1) can be assigned new
"
)
...
...
@@ -162,6 +168,9 @@ class DictOfSeries(OrderedDict):
pass
def
__str__
(
self
):
return
self
.
__repr__
()
def
__repr__
(
self
):
max_rosw
=
pd
.
get_option
(
'
display.max_rows
'
)
pd
.
set_option
(
'
display.max_rows
'
,
dios_options
[
'
disp_max_rows
'
])
...
...
@@ -172,13 +181,13 @@ class DictOfSeries(OrderedDict):
if
len
(
keylist
)
>
max_vars
:
i
=
max_vars
//
2
for
k
in
keylist
[:
i
]:
s
+=
f
'
{
k
}
:
\n
{
self
[
k
]
}
\n
'
kstr
=
str
(
self
[
k
]).
replace
(
'
\n
'
,
'
\n
'
)
s
+=
f
'
{
k
}
:
\n
{
kstr
}
\n
'
s
+=
'
...
\t\t\t\t
...
\n
'
*
2
keylist
=
keylist
[
-
i
:]
for
k
in
keylist
:
s
+=
f
'
{
k
}
:
\n
{
self
[
k
]
}
\n
'
except
Exception
:
raise
kstr
=
str
(
self
[
k
]).
replace
(
'
\n
'
,
'
\n
'
)
s
+=
f
'
{
k
}
:
\n
{
kstr
}
\n
'
finally
:
pd
.
set_option
(
'
display.max_rows
'
,
max_rosw
)
return
s
...
...
@@ -268,6 +277,18 @@ class DictOfSeries(OrderedDict):
def
__xor__
(
self
,
other
):
return
self
.
__op2__
(
other
,
op
.
xor
)
def
__getattr__
(
self
,
item
):
# this is called only(!) if the requested attribute was not found
# (implicit handled by self.__getattribute__).
attr
=
getattr
(
pd
.
Series
,
item
,
None
)
if
attr
is
None
:
raise
AttributeError
(
f
"'
DictOfSeries
'
nor
'
pd.Series
'
objects have an attribute
'
{
item
}
'"
)
if
hasattr
(
attr
,
'
__call__
'
):
return
functools
.
partial
(
self
.
pipe
,
attr
)
else
:
raise
NotImplementedError
(
f
"
cannot propagate non-functions to items of dios
"
)
def
squeeze
(
self
):
if
len
(
self
)
==
1
:
return
self
[
self
.
__keys
[
0
]]
...
...
@@ -325,4 +346,10 @@ class DictOfSeries(OrderedDict):
if
__name__
==
'
__main__
'
:
pass
dios
=
DictOfSeries
(
a
=
[
234.54
,
5
,
5
,
4
,
np
.
nan
,
5
,
4
,
5
])
dios
[
'
b
'
]
=
dios
*
2
dios
.
squeeze
()
print
(
dios
)
dios
.
dropna
(
inplace
=
True
)
print
(
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