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


Python dtypes.DatetimeTZDtype方法代码示例

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


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

示例1: test_frame_no_datetime64_dtype

# 需要导入模块: from pandas.core.dtypes import dtypes [as 别名]
# 或者: from pandas.core.dtypes.dtypes import DatetimeTZDtype [as 别名]
def test_frame_no_datetime64_dtype(self, tz):
        # after GH#7822
        # these retain the timezones on dict construction
        dr = date_range('2011/1/1', '2012/1/1', freq='W-FRI')
        dr_tz = dr.tz_localize(tz)
        df = DataFrame({'A': 'foo', 'B': dr_tz}, index=dr)
        tz_expected = DatetimeTZDtype('ns', dr_tz.tzinfo)
        assert df['B'].dtype == tz_expected

        # GH#2810 (with timezones)
        datetimes_naive = [ts.to_pydatetime() for ts in dr]
        datetimes_with_tz = [ts.to_pydatetime() for ts in dr_tz]
        df = DataFrame({'dr': dr,
                        'dr_tz': dr_tz,
                        'datetimes_naive': datetimes_naive,
                        'datetimes_with_tz': datetimes_with_tz})
        result = df.get_dtype_counts().sort_index()
        expected = Series({'datetime64[ns]': 2,
                           str(tz_expected): 2}).sort_index()
        tm.assert_series_equal(result, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:22,代码来源:test_timezones.py

示例2: _add_datetimelike_scalar

# 需要导入模块: from pandas.core.dtypes import dtypes [as 别名]
# 或者: from pandas.core.dtypes.dtypes import DatetimeTZDtype [as 别名]
def _add_datetimelike_scalar(self, other):
        # adding a timedeltaindex to a datetimelike
        from pandas.core.arrays import DatetimeArray

        assert other is not NaT
        other = Timestamp(other)
        if other is NaT:
            # In this case we specifically interpret NaT as a datetime, not
            # the timedelta interpretation we would get by returning self + NaT
            result = self.asi8.view('m8[ms]') + NaT.to_datetime64()
            return DatetimeArray(result)

        i8 = self.asi8
        result = checked_add_with_arr(i8, other.value,
                                      arr_mask=self._isnan)
        result = self._maybe_mask_results(result)
        dtype = DatetimeTZDtype(tz=other.tz) if other.tz else _NS_DTYPE
        return DatetimeArray(result, dtype=dtype, freq=self.freq) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:20,代码来源:timedeltas.py

示例3: _get_dtype

# 需要导入模块: from pandas.core.dtypes import dtypes [as 别名]
# 或者: from pandas.core.dtypes.dtypes import DatetimeTZDtype [as 别名]
def _get_dtype(self, sqltype):
        from sqlalchemy.types import (Integer, Float, Boolean, DateTime,
                                      Date, TIMESTAMP)

        if isinstance(sqltype, Float):
            return float
        elif isinstance(sqltype, Integer):
            # TODO: Refine integer size.
            return np.dtype('int64')
        elif isinstance(sqltype, TIMESTAMP):
            # we have a timezone capable type
            if not sqltype.timezone:
                return datetime
            return DatetimeTZDtype
        elif isinstance(sqltype, DateTime):
            # Caution: np.datetime64 is also a subclass of np.number.
            return datetime
        elif isinstance(sqltype, Date):
            return date
        elif isinstance(sqltype, Boolean):
            return bool
        return object 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:24,代码来源:sql.py

示例4: test_frame_no_datetime64_dtype

# 需要导入模块: from pandas.core.dtypes import dtypes [as 别名]
# 或者: from pandas.core.dtypes.dtypes import DatetimeTZDtype [as 别名]
def test_frame_no_datetime64_dtype(self):

        # after 7822
        # these retain the timezones on dict construction

        dr = date_range('2011/1/1', '2012/1/1', freq='W-FRI')
        dr_tz = dr.tz_localize(self.tzstr('US/Eastern'))
        e = DataFrame({'A': 'foo', 'B': dr_tz}, index=dr)
        tz_expected = DatetimeTZDtype('ns', dr_tz.tzinfo)
        assert e['B'].dtype == tz_expected

        # GH 2810 (with timezones)
        datetimes_naive = [ts.to_pydatetime() for ts in dr]
        datetimes_with_tz = [ts.to_pydatetime() for ts in dr_tz]
        df = DataFrame({'dr': dr,
                        'dr_tz': dr_tz,
                        'datetimes_naive': datetimes_naive,
                        'datetimes_with_tz': datetimes_with_tz})
        result = df.get_dtype_counts().sort_index()
        expected = Series({'datetime64[ns]': 2,
                           str(tz_expected): 2}).sort_index()
        assert_series_equal(result, expected) 
开发者ID:securityclippy,项目名称:elasticintel,代码行数:24,代码来源:test_timezones.py

示例5: dtype

# 需要导入模块: from pandas.core.dtypes import dtypes [as 别名]
# 或者: from pandas.core.dtypes.dtypes import DatetimeTZDtype [as 别名]
def dtype(request):
    return DatetimeTZDtype(unit="ns", tz=request.param) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:4,代码来源:test_datetime.py

示例6: test_mismatched_timezone_raises

# 需要导入模块: from pandas.core.dtypes import dtypes [as 别名]
# 或者: from pandas.core.dtypes.dtypes import DatetimeTZDtype [as 别名]
def test_mismatched_timezone_raises(self):
        arr = DatetimeArray(np.array(['2000-01-01T06:00:00'], dtype='M8[ns]'),
                            dtype=DatetimeTZDtype(tz='US/Central'))
        dtype = DatetimeTZDtype(tz='US/Eastern')
        with pytest.raises(TypeError, match='Timezone of the array'):
            DatetimeArray(arr, dtype=dtype) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:8,代码来源:test_datetimes.py

示例7: test_astype_to_same

# 需要导入模块: from pandas.core.dtypes import dtypes [as 别名]
# 或者: from pandas.core.dtypes.dtypes import DatetimeTZDtype [as 别名]
def test_astype_to_same(self):
        arr = DatetimeArray._from_sequence(['2000'], tz='US/Central')
        result = arr.astype(DatetimeTZDtype(tz="US/Central"), copy=False)
        assert result is arr 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:6,代码来源:test_datetimes.py

示例8: test_setitem_different_tz_raises

# 需要导入模块: from pandas.core.dtypes import dtypes [as 别名]
# 或者: from pandas.core.dtypes.dtypes import DatetimeTZDtype [as 别名]
def test_setitem_different_tz_raises(self):
        data = np.array([1, 2, 3], dtype='M8[ns]')
        arr = DatetimeArray(data, copy=False,
                            dtype=DatetimeTZDtype(tz="US/Central"))
        with pytest.raises(ValueError, match="None"):
            arr[0] = pd.Timestamp('2000')

        with pytest.raises(ValueError, match="US/Central"):
            arr[0] = pd.Timestamp('2000', tz="US/Eastern") 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:11,代码来源:test_datetimes.py

示例9: test_tz_dtype_mismatch_raises

# 需要导入模块: from pandas.core.dtypes import dtypes [as 别名]
# 或者: from pandas.core.dtypes.dtypes import DatetimeTZDtype [as 别名]
def test_tz_dtype_mismatch_raises(self):
        arr = DatetimeArray._from_sequence(['2000'], tz='US/Central')
        with pytest.raises(TypeError, match='data is already tz-aware'):
            sequence_to_dt64ns(arr, dtype=DatetimeTZDtype(tz="UTC")) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:6,代码来源:test_datetimes.py

示例10: _simple_new

# 需要导入模块: from pandas.core.dtypes import dtypes [as 别名]
# 或者: from pandas.core.dtypes.dtypes import DatetimeTZDtype [as 别名]
def _simple_new(cls, values, name=None, freq=None, tz=None, dtype=None):
        """
        we require the we have a dtype compat for the values
        if we are passed a non-dtype compat, then coerce using the constructor
        """
        if isinstance(values, DatetimeArray):
            if tz:
                tz = validate_tz_from_dtype(dtype, tz)
                dtype = DatetimeTZDtype(tz=tz)
            elif dtype is None:
                dtype = _NS_DTYPE

            values = DatetimeArray(values, freq=freq, dtype=dtype)
            tz = values.tz
            freq = values.freq
            values = values._data

        # DatetimeArray._simple_new will accept either i8 or M8[ns] dtypes
        if isinstance(values, DatetimeIndex):
            values = values._data

        dtype = tz_to_dtype(tz)
        dtarr = DatetimeArray._simple_new(values, freq=freq, dtype=dtype)
        assert isinstance(dtarr, DatetimeArray)

        result = object.__new__(cls)
        result._data = dtarr
        result.name = name
        # For groupby perf. See note in indexes/base about _index_data
        result._index_data = dtarr._data
        result._reset_identity()
        return result

    # -------------------------------------------------------------------- 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:36,代码来源:datetimes.py

示例11: _harmonize_columns

# 需要导入模块: from pandas.core.dtypes import dtypes [as 别名]
# 或者: from pandas.core.dtypes.dtypes import DatetimeTZDtype [as 别名]
def _harmonize_columns(self, parse_dates=None):
        """
        Make the DataFrame's column types align with the SQL table
        column types.
        Need to work around limited NA value support. Floats are always
        fine, ints must always be floats if there are Null values.
        Booleans are hard because converting bool column with None replaces
        all Nones with false. Therefore only convert bool if there are no
        NA values.
        Datetimes should already be converted to np.datetime64 if supported,
        but here we also force conversion if required.
        """
        parse_dates = _process_parse_dates_argument(parse_dates)

        for sql_col in self.table.columns:
            col_name = sql_col.name
            try:
                df_col = self.frame[col_name]

                # Handle date parsing upfront; don't try to convert columns
                # twice
                if col_name in parse_dates:
                    try:
                        fmt = parse_dates[col_name]
                    except TypeError:
                        fmt = None
                    self.frame[col_name] = _handle_date_column(
                        df_col, format=fmt)
                    continue

                # the type the dataframe column should have
                col_type = self._get_dtype(sql_col.type)

                if (col_type is datetime or col_type is date or
                        col_type is DatetimeTZDtype):
                    # Convert tz-aware Datetime SQL columns to UTC
                    utc = col_type is DatetimeTZDtype
                    self.frame[col_name] = _handle_date_column(df_col, utc=utc)
                elif col_type is float:
                    # floats support NA, can always convert!
                    self.frame[col_name] = df_col.astype(col_type, copy=False)

                elif len(df_col) == df_col.count():
                    # No NA values, can convert ints and bools
                    if col_type is np.dtype('int64') or col_type is bool:
                        self.frame[col_name] = df_col.astype(
                            col_type, copy=False)
            except KeyError:
                pass  # this column not in results 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:51,代码来源:sql.py


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