当前位置: 首页>>代码示例>>Python>>正文


Python numpy.isnat方法代码示例

本文整理汇总了Python中numpy.isnat方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.isnat方法的具体用法?Python numpy.isnat怎么用?Python numpy.isnat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在numpy的用法示例。


在下文中一共展示了numpy.isnat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_isnat

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import isnat [as 别名]
def test_isnat(self):
        assert_(np.isnat(np.datetime64('NaT', 'ms')))
        assert_(np.isnat(np.datetime64('NaT', 'ns')))
        assert_(not np.isnat(np.datetime64('2038-01-19T03:14:07')))

        assert_(np.isnat(np.timedelta64('NaT', "ms")))
        assert_(not np.isnat(np.timedelta64(34, "ms")))

        res = np.array([False, False, True])
        for unit in ['Y', 'M', 'W', 'D',
                     'h', 'm', 's', 'ms', 'us',
                     'ns', 'ps', 'fs', 'as']:
            arr = np.array([123, -321, "NaT"], dtype='<datetime64[%s]' % unit)
            assert_equal(np.isnat(arr), res)
            arr = np.array([123, -321, "NaT"], dtype='>datetime64[%s]' % unit)
            assert_equal(np.isnat(arr), res)
            arr = np.array([123, -321, "NaT"], dtype='<timedelta64[%s]' % unit)
            assert_equal(np.isnat(arr), res)
            arr = np.array([123, -321, "NaT"], dtype='>timedelta64[%s]' % unit)
            assert_equal(np.isnat(arr), res) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:22,代码来源:test_datetime.py

示例2: get_datetime_str

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import isnat [as 别名]
def get_datetime_str(arr: ndarray):
    dt = {0: 'ns', 1: 'us', 2: 'ms', 3: 's', 4: 'D'}
    arr = arr[~np.isnat(arr)].view('int64')
    counts = np.zeros(len(arr), dtype='int64')
    for i, val in enumerate(arr):
        if val == 0:
            counts[i] = 4
            continue
        dec = decimal.Decimal(int(val)).as_tuple()
        ct = 0

        for digit in dec.digits[::-1]:
            if digit == 0:
                ct += 1
            else:
                break

        if ct >= 11:
            counts[i] = 4
        else:
            counts[i] = ct // 3

    return dt[counts.min()] 
开发者ID:dexplo,项目名称:dexplo,代码行数:25,代码来源:_utils.py

示例3: isna_overload

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import isnat [as 别名]
def isna_overload(arr, i):
    if arr == string_array_type:
        return lambda arr, i: sdc.str_arr_ext.str_arr_is_na(arr, i)
    # TODO: support NaN in list(list(str))
    if arr == list_string_array_type:
        return lambda arr, i: False
    # TODO: extend to other types
    assert isinstance(arr, types.Array) or isinstance(arr, types.List)
    dtype = arr.dtype
    if isinstance(dtype, types.Float):
        return lambda arr, i: np.isnan(arr[i])

    # NaT for dt64
    if isinstance(dtype, (types.NPDatetime, types.NPTimedelta)):
        nat = dtype('NaT')
        # TODO: replace with np.isnat
        return lambda arr, i: arr[i] == nat

    # XXX integers don't have nans, extend to boolean
    return lambda arr, i: False 
开发者ID:IntelPython,项目名称:sdc,代码行数:22,代码来源:api.py

示例4: isnat

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import isnat [as 别名]
def isnat(val):
    """
    Checks if the value is a NaT. Should only be called on datetimelike objects.
    """
    if (isinstance(val, (np.datetime64, np.timedelta64)) or
        (isinstance(val, np.ndarray) and val.dtype.kind == 'M')):
        if numpy_version >= '1.13':
            return np.isnat(val)
        else:
            return val.view('i8') == nat_as_integer
    elif pd and val is pd.NaT:
        return True
    elif pd and isinstance(val, pandas_datetime_types+pandas_timedelta_types):
        return pd.isna(val)
    else:
        return False 
开发者ID:holoviz,项目名称:holoviews,代码行数:18,代码来源:util.py

示例5: test_get_timestamps

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import isnat [as 别名]
def test_get_timestamps(self):
        """Test getting the timestamps."""
        tline = self.reader._get_timestamps()

        # First and last scanline have invalid timestamps (space)
        self.assertTrue(np.isnat(tline[0]))
        self.assertTrue(np.isnat(tline[-1]))

        # Test remaining lines
        year = tline.astype('datetime64[Y]').astype(int) + 1970
        month = tline.astype('datetime64[M]').astype(int) % 12 + 1
        day = (tline.astype('datetime64[D]') - tline.astype('datetime64[M]') + 1).astype(int)
        msec = (tline - tline.astype('datetime64[D]')).astype(int)
        self.assertTrue(np.all(year[1:-1] == 2016))
        self.assertTrue(np.all(month[1:-1] == 3))
        self.assertTrue(np.all(day[1:-1] == 3))
        self.assertTrue(np.all(msec[1:-1] == np.arange(len(tline) - 2))) 
开发者ID:pytroll,项目名称:satpy,代码行数:19,代码来源:test_seviri_l1b_hrit.py

示例6: set_jds

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import isnat [as 别名]
def set_jds(self, val1, val2):
        # If there are any masked values in the ``val1`` datetime64 array
        # ('NaT') then stub them with a valid date so downstream parse_string
        # will work.  The value under the mask is arbitrary but a "modern" date
        # is good.
        mask = np.isnat(val1)
        masked = np.any(mask)
        if masked:
            val1 = val1.copy()
            val1[mask] = '2000'

        # Make sure M(onth) and Y(ear) dates will parse and convert to bytestring
        if val1.dtype.name in ['datetime64[M]', 'datetime64[Y]']:
            val1 = val1.astype('datetime64[D]')
        val1 = val1.astype('S')

        # Standard ISO string parsing now
        super().set_jds(val1, val2)

        # Finally apply mask if necessary
        if masked:
            self.jd2[mask] = np.nan 
开发者ID:holzschu,项目名称:Carnets,代码行数:24,代码来源:formats.py

示例7: test_isnat_error

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import isnat [as 别名]
def test_isnat_error(self):
        # Test that only datetime dtype arrays are accepted
        for t in np.typecodes["All"]:
            if t in np.typecodes["Datetime"]:
                continue
            assert_raises(TypeError, np.isnat, np.zeros(10, t)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:8,代码来源:test_datetime.py

示例8: _day

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import isnat [as 别名]
def _day(self, data):
        if data.size < 5000:
            days = (data.astype('datetime64[D]') - data.astype('datetime64[M]') + 1).astype('float64')
            days[np.isnat(data)] = nan
        else:
            return _date.day(data.astype('int64'))
        return days 
开发者ID:dexplo,项目名称:dexplo,代码行数:9,代码来源:_date.py

示例9: _day_of_year

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import isnat [as 别名]
def _day_of_year(self, data):
        if data.size < 2500:
            doy = (data.astype('datetime64[D]') - data.astype('datetime64[Y]') + 1).astype('float64')
            doy[np.isnat(data)] = nan
            return doy
        else:
            return _date.day_of_year(data.astype('int64')) 
开发者ID:dexplo,项目名称:dexplo,代码行数:9,代码来源:_date.py

示例10: _days_in_month

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import isnat [as 别名]
def _days_in_month(self, data):
        if data.size < 5000:
            month = data.astype('datetime64[M]')
            next_month = (month + 1).astype('datetime64[D]')
            dim = (next_month - month).astype('float64')
            dim[np.isnat(data)] = nan
            return dim
        else:
            return _date.days_in_month(data.astype('int64')) 
开发者ID:dexplo,项目名称:dexplo,代码行数:11,代码来源:_date.py

示例11: _is_leap_year

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import isnat [as 别名]
def _is_leap_year(self, data):
        if data.size < 500:
            years = data.astype('datetime64[Y]').astype('float64') + 1970
            years[np.isnat(data)] = nan
            return np.where(years % 4 == 0, np.where(years % 100 == 0,
                                              np.where(years % 400 == 0, True, False), True), False)
        else:
            return _date.is_leap_year(data.astype('int64')) 
开发者ID:dexplo,项目名称:dexplo,代码行数:10,代码来源:_date.py

示例12: _quarter

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import isnat [as 别名]
def _quarter(self, data):
        if data.size < 5000:
            t = data.astype('datetime64[M]').astype('float64') % 12 // 3 + 1
            t[np.isnat(data)] = nan
            return t
        else:
            return _date.quarter(data.astype('int64')) 
开发者ID:dexplo,项目名称:dexplo,代码行数:9,代码来源:_date.py

示例13: _seconds

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import isnat [as 别名]
def _seconds(self, data, total):
        if total:
            t = data.astype('float64') / 10 ** 9
            t[np.isnat(data)] = nan
            return t
        else:
            return _td.seconds(data.astype('int64')) 
开发者ID:dexplo,项目名称:dexplo,代码行数:9,代码来源:_date.py

示例14: any_date

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import isnat [as 别名]
def any_date(arr, axis, **kwargs):
    return (~np.isnat(arr)).sum(axis=axis) > 0 
开发者ID:dexplo,项目名称:dexplo,代码行数:4,代码来源:_date_funcs.py

示例15: all_date

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import isnat [as 别名]
def all_date(arr, axis, **kwargs):
    return (~np.isnat(arr)).sum(axis=axis) == arr.shape[0] 
开发者ID:dexplo,项目名称:dexplo,代码行数:4,代码来源:_date_funcs.py


注:本文中的numpy.isnat方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。