mirror of
https://github.com/meteoinfo/MeteoInfo.git
synced 2025-12-08 20:36:05 +00:00
bugfix for find common data type from arrays and scalars
This commit is contained in:
parent
aff5cb8722
commit
e7f88b3eee
@ -1,34 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<MeteoInfo File="milconfig.xml" Type="configurefile">
|
||||
<Path OpenPath="D:\Working\MIScript\Jython\mis\io\grib">
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d"/>
|
||||
<Path OpenPath="D:\Working\MIScript\Jython\mis\common_math\signal">
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\plot_types\3d\jogl\plot"/>
|
||||
<RecentFolder Folder="D:\Temp\test"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\array"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math\stats"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\dataframe"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\netcdf"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\burf"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\test"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\dataconvert"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\io\grib"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\array"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math"/>
|
||||
<RecentFolder Folder="D:\Working\MIScript\Jython\mis\common_math\signal"/>
|
||||
</Path>
|
||||
<File>
|
||||
<OpenedFiles>
|
||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\io\radar\radar_x_phase_2.py"/>
|
||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\io\dataconvert\grib2nc-5.py"/>
|
||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\io\grib\s2s_babj_1.py"/>
|
||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\io\grib\s2s_babj_2.py"/>
|
||||
<OpenedFile File="D:\Working\MIScript\Jython\mis\common_math\signal\detrend.py"/>
|
||||
</OpenedFiles>
|
||||
<RecentFiles>
|
||||
<RecentFile File="D:\Working\MIScript\Jython\mis\io\radar\radar_x_phase_2.py"/>
|
||||
<RecentFile File="D:\Working\MIScript\Jython\mis\io\dataconvert\grib2nc-5.py"/>
|
||||
<RecentFile File="D:\Working\MIScript\Jython\mis\io\grib\s2s_babj_1.py"/>
|
||||
<RecentFile File="D:\Working\MIScript\Jython\mis\io\grib\s2s_babj_2.py"/>
|
||||
<RecentFile File="D:\Working\MIScript\Jython\mis\common_math\signal\detrend.py"/>
|
||||
</RecentFiles>
|
||||
</File>
|
||||
<Font>
|
||||
@ -36,5 +34,5 @@
|
||||
</Font>
|
||||
<LookFeel DockWindowDecorated="true" LafDecorated="true" Name="FlatDarkLaf"/>
|
||||
<Figure DoubleBuffering="true"/>
|
||||
<Startup MainFormLocation="-6,-6" MainFormSize="1292,764"/>
|
||||
<Startup MainFormLocation="8,11" MainFormSize="1292,764"/>
|
||||
</MeteoInfo>
|
||||
|
||||
Binary file not shown.
@ -141,19 +141,22 @@ class DataType(object):
|
||||
|
||||
:return: kind string
|
||||
"""
|
||||
if self.name == 'bool' or self.name == 'boolean':
|
||||
if self._dtype == JDataType.BOOLEAN:
|
||||
return 'b'
|
||||
elif self.name == 'int' or self.name == 'integer' or self.name == 'int32' or self.name == 'int16' or \
|
||||
self.name == 'uint' or self.name == 'short' or self.name == 'int64' or self.name == 'long':
|
||||
elif self._dtype in (JDataType.SHORT, JDataType.INT, JDataType.LONG):
|
||||
return 'i'
|
||||
elif self.name == 'float' or self.name == 'float64' or self.name == 'double':
|
||||
elif self._dtype == JDataType.UINT:
|
||||
return 'u'
|
||||
elif self._dtype in (JDataType.FLOAT, JDataType.DOUBLE):
|
||||
return 'f'
|
||||
elif self.name == 'str' or self.name == 'string':
|
||||
elif self._dtype == JDataType.STRING:
|
||||
return 'S'
|
||||
elif self.name == 'complex':
|
||||
elif self._dtype == JDataType.COMPLEX:
|
||||
return 'c'
|
||||
elif self.name == 'date' or self.name == 'datetime':
|
||||
elif self._dtype == JDataType.DATE:
|
||||
return 'M'
|
||||
elif self._dtype == JDataType.OBJECT:
|
||||
return 'O'
|
||||
|
||||
@staticmethod
|
||||
def from_char(c):
|
||||
@ -163,9 +166,9 @@ class DataType(object):
|
||||
:return: The DataType
|
||||
"""
|
||||
if c == 'b' or c == 'bool':
|
||||
return DataType('boolean')
|
||||
return dtype.bool
|
||||
elif c == 'h':
|
||||
return DataType('short')
|
||||
return dtype.short
|
||||
elif c == 'l' or c == 'int':
|
||||
return DataType('int')
|
||||
elif c == 'q':
|
||||
@ -183,6 +186,30 @@ class DataType(object):
|
||||
else:
|
||||
return DataType('object')
|
||||
|
||||
@staticmethod
|
||||
def from_kind(k):
|
||||
"""
|
||||
Create DataType from kind.
|
||||
:param k: (*str*) Kind string.
|
||||
:return: The DataType
|
||||
"""
|
||||
if k == 'b':
|
||||
return dtype.bool
|
||||
elif k == 'i':
|
||||
return dtype.int
|
||||
elif k == 'u':
|
||||
return dtype.uint
|
||||
elif k == 'f':
|
||||
return dtype.float
|
||||
elif k == 'S':
|
||||
return dtype.string
|
||||
elif k == 'c':
|
||||
return dtype.complex
|
||||
elif k == 'M':
|
||||
return dtype.date
|
||||
else:
|
||||
return dtype.obj
|
||||
|
||||
def is_numeric(self):
|
||||
"""
|
||||
Is numeric data type or not.
|
||||
@ -217,7 +244,10 @@ class dtype(DataType):
|
||||
obj = DataType('object')
|
||||
|
||||
def __init__(self, name):
|
||||
super(dtype, self).__init__(name)
|
||||
if isinstance(name, DataType):
|
||||
DataType.__init__(self, name.name)
|
||||
else:
|
||||
DataType.__init__(self, name)
|
||||
|
||||
@staticmethod
|
||||
def fromjava(dt):
|
||||
|
||||
Binary file not shown.
@ -35,9 +35,10 @@ typecodes = {'Character':'c',
|
||||
# U -> Unicode string
|
||||
# V -> record
|
||||
# O -> Python object
|
||||
_kind_list = ['b', 'u', 'i', 'f', 'c', 'S', 'U', 'V', 'O', 'M', 'm']
|
||||
_kind_list = ['b', 'i', 'u', 'f', 'c', 'S', 'U', 'V', 'O', 'M', 'm']
|
||||
_char_list = ['b','h','l','q','f','d','D','U','M','O']
|
||||
|
||||
__test_types = '?'+typecodes['AllInteger'][:-2]+typecodes['AllFloat']+'O'
|
||||
__test_types = _char_list
|
||||
__len_test_types = len(__test_types)
|
||||
|
||||
# Keep incrementing until a common type both can be coerced to
|
||||
@ -60,7 +61,7 @@ def _can_coerce_all(dtypelist, start=0):
|
||||
return dtypelist[0]
|
||||
thisind = start
|
||||
while thisind < __len_test_types:
|
||||
newdtype = dtype(__test_types[thisind])
|
||||
newdtype = dtype.from_char(__test_types[thisind])
|
||||
numcoerce = len([x for x in dtypelist if newdtype >= x])
|
||||
if numcoerce == N:
|
||||
return newdtype
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user