def to_pydatetime(self): """ Return DatetimeIndex as object ndarray of datetime.datetime objects Returns ------- datetimes : ndarray """ return lib.ints_to_pydatetime(self.asi8, tz=self.tz)
def _astype_nansafe(arr, dtype): if isinstance(dtype, basestring): dtype = np.dtype(dtype) if issubclass(arr.dtype.type, np.datetime64): if dtype == object: return lib.ints_to_pydatetime(arr.view(np.int64)) elif np.issubdtype(arr.dtype, np.floating) and np.issubdtype(dtype, np.integer): if np.isnan(arr).any(): raise ValueError("Cannot convert NA to integer") return arr.astype(dtype)
def _astype_nansafe(arr, dtype): if isinstance(dtype, basestring): dtype = np.dtype(dtype) if issubclass(arr.dtype.type, np.datetime64): if dtype == object: return lib.ints_to_pydatetime(arr.view(np.int64)) elif (np.issubdtype(arr.dtype, np.floating) and np.issubdtype(dtype, np.integer)): if np.isnan(arr).any(): raise ValueError('Cannot convert NA to integer') return arr.astype(dtype)
def _astype_nansafe(arr, dtype): if not isinstance(dtype, np.dtype): dtype = np.dtype(dtype) if issubclass(arr.dtype.type, np.datetime64): if dtype == object: return lib.ints_to_pydatetime(arr.view(np.int64)) elif np.issubdtype(arr.dtype, np.floating) and np.issubdtype(dtype, np.integer): if np.isnan(arr).any(): raise ValueError("Cannot convert NA to integer") elif arr.dtype == np.object_ and np.issubdtype(dtype.type, np.integer): # work around NumPy brokenness, #1987 return lib.astype_intsafe(arr.ravel(), dtype).reshape(arr.shape) return arr.astype(dtype)
def _astype_nansafe(arr, dtype): if not isinstance(dtype, np.dtype): dtype = np.dtype(dtype) if issubclass(arr.dtype.type, np.datetime64): if dtype == object: return lib.ints_to_pydatetime(arr.view(np.int64)) elif (np.issubdtype(arr.dtype, np.floating) and np.issubdtype(dtype, np.integer)): if np.isnan(arr).any(): raise ValueError('Cannot convert NA to integer') elif arr.dtype == np.object_ and np.issubdtype(dtype.type, np.integer): # work around NumPy brokenness, #1987 return lib.astype_intsafe(arr.ravel(), dtype).reshape(arr.shape) return arr.astype(dtype)
def get_values(self, dtype): if dtype == object: flat_i8 = self.values.ravel().view(np.int64) res = lib.ints_to_pydatetime(flat_i8) return res.reshape(self.values.shape) return self.values
def _mpl_repr(self): # how to represent ourselves to matplotlib return lib.ints_to_pydatetime(self.asi8)
# <codecell> from pandas import lib from matplotlib.ticker import FuncFormatter fig, axes = plt.subplots(figsize=(12,8)) data = group[["poll_date", "obama_spread"]] data = pandas.concat((data, national_data2012[["poll_date", "obama_spread"]])) data.sort("poll_date", inplace=True) dates = pandas.DatetimeIndex(data.poll_date).asi8 loess_res = sm.nonparametric.lowess(data.obama_spread.values, dates, frac=.2, it=3) dates_x = lib.ints_to_pydatetime(dates) axes.scatter(dates_x, data["obama_spread"]) axes.plot(dates_x, loess_res[:,1], color='r') axes.yaxis.get_major_locator().set_params(nbins=12) axes.yaxis.set_major_formatter(FuncFormatter(edit_tick_label)) axes.grid(False, axis='x') axes.hlines(0, dates_x[0], dates_x[-1], color='black', lw=3) axes.margins(0, .05) # <codecell> loess_res[-7:,1].mean() # <codecell> from pandas import lib