當前位置: 首頁>>代碼示例>>Python>>正文


Python dtypes.PeriodDtype方法代碼示例

本文整理匯總了Python中pandas.core.dtypes.dtypes.PeriodDtype方法的典型用法代碼示例。如果您正苦於以下問題:Python dtypes.PeriodDtype方法的具體用法?Python dtypes.PeriodDtype怎麽用?Python dtypes.PeriodDtype使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pandas.core.dtypes.dtypes的用法示例。


在下文中一共展示了dtypes.PeriodDtype方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _from_sequence

# 需要導入模塊: from pandas.core.dtypes import dtypes [as 別名]
# 或者: from pandas.core.dtypes.dtypes import PeriodDtype [as 別名]
def _from_sequence(cls, scalars, dtype=None, copy=False):
        # type: (Sequence[Optional[Period]], PeriodDtype, bool) -> PeriodArray
        if dtype:
            freq = dtype.freq
        else:
            freq = None

        if isinstance(scalars, cls):
            validate_dtype_freq(scalars.dtype, freq)
            if copy:
                scalars = scalars.copy()
            return scalars

        periods = np.asarray(scalars, dtype=object)
        if copy:
            periods = periods.copy()

        freq = freq or libperiod.extract_freq(periods)
        ordinals = libperiod.extract_ordinals(periods, freq)
        return cls(ordinals, freq=freq) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:22,代碼來源:period.py

示例2: dtype

# 需要導入模塊: from pandas.core.dtypes import dtypes [as 別名]
# 或者: from pandas.core.dtypes.dtypes import PeriodDtype [as 別名]
def dtype():
    return PeriodDtype(freq='D') 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:4,代碼來源:test_period.py

示例3: test_registered

# 需要導入模塊: from pandas.core.dtypes import dtypes [as 別名]
# 或者: from pandas.core.dtypes.dtypes import PeriodDtype [as 別名]
def test_registered():
    assert PeriodDtype in registry.dtypes
    result = registry.find("Period[D]")
    expected = PeriodDtype("D")
    assert result == expected

# ----------------------------------------------------------------------------
# period_array 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:10,代碼來源:test_period.py

示例4: test_astype_period

# 需要導入模塊: from pandas.core.dtypes import dtypes [as 別名]
# 或者: from pandas.core.dtypes.dtypes import PeriodDtype [as 別名]
def test_astype_period():
    arr = period_array(['2000', '2001', None], freq='D')
    result = arr.astype(PeriodDtype("M"))
    expected = period_array(['2000', '2001', None], freq='M')
    tm.assert_period_array_equal(result, expected) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:7,代碼來源:test_period.py

示例5: test_constructor_cast_object

# 需要導入模塊: from pandas.core.dtypes import dtypes [as 別名]
# 或者: from pandas.core.dtypes.dtypes import PeriodDtype [as 別名]
def test_constructor_cast_object(self):
        s = Series(period_range('1/1/2000', periods=10),
                   dtype=PeriodDtype("D"))
        exp = Series(period_range('1/1/2000', periods=10))
        tm.assert_series_equal(s, exp) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:7,代碼來源:test_construction.py

示例6: validate_dtype_freq

# 需要導入模塊: from pandas.core.dtypes import dtypes [as 別名]
# 或者: from pandas.core.dtypes.dtypes import PeriodDtype [as 別名]
def validate_dtype_freq(dtype, freq):
    """
    If both a dtype and a freq are available, ensure they match.  If only
    dtype is available, extract the implied freq.

    Parameters
    ----------
    dtype : dtype
    freq : DateOffset or None

    Returns
    -------
    freq : DateOffset

    Raises
    ------
    ValueError : non-period dtype
    IncompatibleFrequency : mismatch between dtype and freq
    """
    if freq is not None:
        freq = frequencies.to_offset(freq)

    if dtype is not None:
        dtype = pandas_dtype(dtype)
        if not is_period_dtype(dtype):
            raise ValueError('dtype must be PeriodDtype')
        if freq is None:
            freq = dtype.freq
        elif freq != dtype.freq:
            raise IncompatibleFrequency('specified freq and dtype '
                                        'are different')
    return freq 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:34,代碼來源:period.py

示例7: _period_array_cmp

# 需要導入模塊: from pandas.core.dtypes import dtypes [as 別名]
# 或者: from pandas.core.dtypes.dtypes import PeriodDtype [as 別名]
def _period_array_cmp(cls, op):
    """
    Wrap comparison operations to convert Period-like to PeriodDtype
    """
    opname = '__{name}__'.format(name=op.__name__)
    nat_result = True if opname == '__ne__' else False

    def wrapper(self, other):
        op = getattr(self.asi8, opname)

        if isinstance(other, (ABCDataFrame, ABCSeries, ABCIndexClass)):
            return NotImplemented

        if is_list_like(other) and len(other) != len(self):
            raise ValueError("Lengths must match")

        if isinstance(other, Period):
            self._check_compatible_with(other)

            result = op(other.ordinal)
        elif isinstance(other, cls):
            self._check_compatible_with(other)

            result = op(other.asi8)

            mask = self._isnan | other._isnan
            if mask.any():
                result[mask] = nat_result

            return result
        elif other is NaT:
            result = np.empty(len(self.asi8), dtype=bool)
            result.fill(nat_result)
        else:
            other = Period(other, freq=self.freq)
            result = op(other.ordinal)

        if self._hasnans:
            result[self._isnan] = nat_result

        return result

    return compat.set_function_name(wrapper, opname, cls) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:45,代碼來源:period.py


注:本文中的pandas.core.dtypes.dtypes.PeriodDtype方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。