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
faf9054d
Commit
faf9054d
authored
5 years ago
by
Bert Palm
🎇
Browse files
Options
Downloads
Patches
Plain Diff
added copy_empty(), warn/err/ignore option
parent
7fb7eb6a
No related branches found
No related tags found
2 merge requests
!2
Develop
,
!1
complete rework
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
dios/dios.py
+15
-10
15 additions, 10 deletions
dios/dios.py
dios/lib.py
+8
-2
8 additions, 2 deletions
dios/lib.py
dios/options.py
+2
-0
2 additions, 0 deletions
dios/options.py
tests/run_dios.py
+2
-0
2 additions, 0 deletions
tests/run_dios.py
with
27 additions
and
12 deletions
dios/dios.py
+
15
−
10
View file @
faf9054d
...
...
@@ -175,8 +175,9 @@ class DictOfSeries:
self
.
_itype
=
itype
if
not
itype
.
unique
:
throw
(
f
"
Using a
{
itype
}
as dios.itype is experimental. As soon as series with different index types
"
f
"
are inserted, slicing will almost always fail. You are hereby warned!
"
,
ItypeWarning
)
throwMixedItypeErrWarn
(
f
"
Using a
{
itype
}
as dios.itype is experimental. As soon as series with
"
f
"
different index types are inserted, slicing will almost always fail.
"
f
"
You are hereby warned!
"
)
def
__cast_all
(
self
,
itype
):
for
k
in
self
.
columns
:
...
...
@@ -223,14 +224,14 @@ class DictOfSeries:
return
self
.
_data
[
key
]
def
_getitem_listlike
(
self
,
keys
):
new
=
DictOfSeries
()
new
=
self
.
copy_empty
()
for
k
in
keys
:
new
[
k
]
=
self
.
_get_item
(
k
)
return
new
def
_slice
(
self
,
keys
,
slicer
):
"""
Return a slice of self
"""
new
=
DictOfSeries
()
new
=
self
.
copy_empty
()
for
k
in
keys
:
new
[
k
]
=
self
.
_get_item
(
k
)[
slicer
]
return
new
...
...
@@ -411,9 +412,13 @@ class DictOfSeries:
def
__deepcopy__
(
self
,
memo
=
None
):
return
self
.
copy
(
deep
=
True
)
def
copy
(
self
,
deep
=
True
):
def
copy
_empty
(
self
):
new
=
DictOfSeries
()
new
.
_itype
=
self
.
itype
return
new
def
copy
(
self
,
deep
=
True
):
new
=
self
.
copy_empty
()
# 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__``.
...
...
@@ -423,13 +428,13 @@ class DictOfSeries:
return
new
def
__op1__
(
self
,
op
):
new
=
DictOfSeries
()
new
=
self
.
copy_empty
()
for
k
in
self
.
columns
:
new
[
k
]
=
op
(
self
[
k
])
return
new
def
__op2__
(
self
,
other
,
op
):
new
=
DictOfSeries
()
new
=
self
.
copy_empty
()
if
isinstance
(
other
,
DictOfSeries
):
keys
=
get_dios_to_dios_keys
(
self
.
columns
,
other
)
for
k
in
keys
:
...
...
@@ -521,7 +526,7 @@ class DictOfSeries:
:return:
"""
news
=
pd
.
Series
()
newd
=
DictOfSeries
()
newd
=
self
.
copy_empty
()
need_dios
=
False
# return a copy nevertheless, but also run inplace if inplace=True or
# if the function not has this option, but work inplace.
...
...
@@ -571,7 +576,7 @@ class _LocIndexer(_Indexer):
def
__getitem__
(
self
,
key
):
rkey
,
cols
=
self
.
_unpack_key
(
key
)
new
=
DictOfSeries
()
new
=
self
.
_dios
.
copy_empty
()
for
c
in
cols
:
new
[
c
]
=
self
.
_data
[
c
].
loc
[
rkey
]
return
new
...
...
@@ -634,7 +639,7 @@ class _iLocIndexer(_Indexer):
def
__getitem__
(
self
,
key
):
rkey
,
cols
=
self
.
_unpack_key
(
key
)
new
=
DictOfSeries
()
new
=
self
.
_dios
.
copy_empty
()
for
c
in
cols
:
new
[
c
]
=
self
.
_data
[
c
].
iloc
[
rkey
]
return
new
...
...
This diff is collapsed.
Click to expand it.
dios/lib.py
+
8
−
2
View file @
faf9054d
...
...
@@ -8,8 +8,14 @@ def _get_storage_class_values(cls):
return
[
getattr
(
cls
,
c
)
for
c
in
cls
.
__dict__
if
not
c
.
startswith
(
"
_
"
)]
def
throw
(
msg
,
wtype
):
warnings
.
warn
(
msg
,
wtype
)
def
throwMixedItypeErrWarn
(
msg
):
if
dios_options
[
Options
.
mixed_itype_policy
]
==
'
ignore
'
:
pass
elif
dios_options
[
Options
.
mixed_itype_policy
]
==
'
error
'
:
raise
ItypeCastError
(
msg
)
else
:
warnings
.
warn
(
msg
,
ItypeWarning
)
return
# todo: make method an kwarg and remove dios_options access
...
...
This diff is collapsed.
Click to expand it.
dios/options.py
+
2
−
0
View file @
faf9054d
...
...
@@ -23,10 +23,12 @@ class Options:
otherwise its the same than creating a new dios)
"""
dios_to_dios_method
=
"
dios_to_dios_method
"
mixed_itype_policy
=
"
mixed_itype_policy
"
# set default values
dios_options
=
{
Options
.
disp_max_rows
:
10
,
Options
.
disp_max_vars
:
4
,
Options
.
dios_to_dios_method
:
3
,
Options
.
mixed_itype_policy
:
'
warn
'
,
}
This diff is collapsed.
Click to expand it.
tests/run_dios.py
+
2
−
0
View file @
faf9054d
...
...
@@ -3,6 +3,8 @@ from dios import *
import
numpy
as
np
if
__name__
==
'
__main__
'
:
dios_options
[
Options
.
mixed_itype_policy
]
=
'
ignore
'
dios
=
DictOfSeries
(
data
=
[
234.54
,
5
,
5
,
4
,
np
.
nan
,
5
,
4
,
5
])
dtser
=
pd
.
Series
([
2
,
4
,
4123
,
122
,
4
],
index
=
pd
.
date_range
(
freq
=
'
1d
'
,
periods
=
5
,
start
=
'
2000-01-01
'
))
dios
[
'
b
'
]
=
dtser
...
...
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