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
7fb7eb6a
Commit
7fb7eb6a
authored
5 years ago
by
Bert Palm
🎇
Browse files
Options
Downloads
Patches
Plain Diff
fixed bugs and minor animals
parent
680ea4a8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!2
Develop
,
!1
complete rework
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
dios/dios.py
+20
-12
20 additions, 12 deletions
dios/dios.py
dios/itypes.py
+11
-5
11 additions, 5 deletions
dios/itypes.py
tests/run_dios.py
+5
-5
5 additions, 5 deletions
tests/run_dios.py
with
36 additions
and
22 deletions
dios/dios.py
+
20
−
12
View file @
7fb7eb6a
...
...
@@ -54,7 +54,7 @@ class DictOfSeries:
"""
def
__init__
(
self
,
data
=
None
,
itype
=
Non
e
,
columns
=
None
):
def
__init__
(
self
,
data
=
None
,
itype
=
MixedItyp
e
,
columns
=
None
):
self
.
_data
=
OrderedDict
()
...
...
@@ -67,10 +67,12 @@ class DictOfSeries:
# which may prevent inserting series with other (higher) itypes.
self
.
_itype
=
MixedItype
self
.
__init_insert_data__
(
data
)
if
data
is
not
None
:
self
.
__init_insert_data__
(
data
)
# we use the columns.setter to make all necessary checks
self
.
columns
=
columns
if
columns
is
not
None
:
self
.
columns
=
columns
# infer the itype by the data
inferred_itype
=
self
.
__find_least_common_itype
()
...
...
@@ -78,12 +80,14 @@ class DictOfSeries:
# We use the itype.setter to make all checks. If the given itype was of a lower type
# than the inferred itype, a cast is tried on every series.
self
.
itype
=
itype
if
itype
is
not
None
:
self
.
itype
=
itype
def
__init_insert_data__
(
self
,
data
):
if
data
is
Non
e
:
return
# user created a empty dios: data=None(->inferred=None), itype=None
els
e
:
self
.
_itype
=
None
def
__init_insert_data__
(
self
,
data
):
if
isinstance
(
data
,
DictOfSeries
):
for
k
in
data
:
self
[
k
]
=
data
[
k
]
...
...
@@ -112,6 +116,9 @@ class DictOfSeries:
for
k
in
self
.
columns
:
itypes
.
append
(
get_itype
(
self
.
_data
[
k
].
index
))
if
not
itypes
:
return
None
found
=
None
# check supertypes
...
...
@@ -127,7 +134,7 @@ class DictOfSeries:
single_itypes
=
[
DatetimeItype
,
IntegerItype
,
FloatItype
]
for
single_itype
in
single_itypes
:
if
all_itypes_le
(
itypes
,
single_itype
):
found
=
single_itype
s
found
=
single_itype
break
return
found
...
...
@@ -291,16 +298,17 @@ class DictOfSeries:
if
not
isinstance
(
v
,
pd
.
Series
):
raise
ValueError
(
f
"
Only pd.Series and DictOfSeries (of length 1) can be assigned new
"
)
itype
=
get_itype
(
v
.
index
)
if
self
.
_itype
is
None
:
# if the user created a empty dios or
# the last emelent was deleted
self
.
_itype
=
get_itype
(
v
.
index
)
# if the user created a empty dios
self
.
_itype
=
itype
v
=
cast_to_fit_itype
(
v
,
self
.
_itype
)
if
v
is
None
:
itype
=
get_itype
(
v
.
index
)
raise
ValueError
(
f
"
Itype mismach. Data of key `
{
key
}
`, with (infered) itype `
{
itype
}
`
"
f
"
cannot be inserted in a dios with itype `
{
self
.
itype
}
`.
"
)
self
.
_data
[
key
]
=
v
.
copy
(
deep
=
True
)
def
_setitem
(
self
,
key
,
val
,
sl
=
None
):
...
...
This diff is collapsed.
Click to expand it.
dios/itypes.py
+
11
−
5
View file @
7fb7eb6a
...
...
@@ -59,24 +59,31 @@ class MixedItype(__Itype):
def
is_itype
(
obj
,
itype
):
"""
Check if obj is a instance of the given itype or its str-alias was given
"""
# todo: iter through itype as it could be a tuple, if called like ``is_itype(o, (t1,t2))``
# user gave a Itype, like ``DatetimeItype``
if
issubclass
(
obj
,
itype
):
if
type
(
obj
)
==
type
and
issubclass
(
obj
,
itype
):
return
True
# todo: iter through itype as it could be a tuple, if called like ``is_itype(o, (t1,t2))``
# user gave a string, like 'datetime'
if
isinstance
(
obj
,
str
)
and
obj
==
itype
.
name
:
return
True
return
False
def
is_itype_subtype
(
obj
,
itype
):
"""
Check if obj is a subclass or a instance of a subclass of the given itype
"""
# user gave a subtype, like ``pd.DatetimeIndex``
if
issubclass
(
obj
,
itype
.
subtypes
):
if
type
(
obj
)
==
type
and
issubclass
(
obj
,
itype
.
subtypes
):
return
True
# user gave a instance of a subtype, like ``pd.Series(..).index``
if
isinstance
(
obj
,
itype
.
subtypes
):
return
True
return
False
...
...
@@ -94,8 +101,7 @@ def get_itype(obj):
- pd.DatetimeIndex
and return the according Itype
"""
# shortcut
if
issubclass
(
obj
,
__Itype
):
if
type
(
obj
)
==
type
and
issubclass
(
obj
,
__Itype
):
return
obj
# check if it is the actual type, not a subtype
...
...
This diff is collapsed.
Click to expand it.
tests/run_dios.py
+
5
−
5
View file @
7fb7eb6a
from
dios
import
*
import
numpy
as
np
if
__name__
==
'
__main__
'
:
dios
=
DictOfSeries
(
a
=
[
234.54
,
5
,
5
,
4
,
np
.
nan
,
5
,
4
,
5
])
# dios['b'] = pd.Series([2,4,4123,122,4], pd.date_range(freq='1d', periods=5, start='2000-01-01'))
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
dios2
=
dios
.
copy
()
dios_options
[
Options
.
allow_mixed_itypes
]
=
True
a
=
dios
.
loc
[:]
df
=
pd
.
DataFrame
([
1
,
24
,
5
,
456
,
45
],
index
=
pd
.
date_range
(
periods
=
5
,
freq
=
'
1d
'
,
start
=
'
2000-01-01
'
))
a
=
df
.
iloc
[:,
0
]
print
(
a
)
print
(
dios
)
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