Пример #1
0
    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)
Пример #2
0
    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)
Пример #3
0
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)
Пример #4
0
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)
Пример #5
0
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)
Пример #6
0
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)
Пример #7
0
 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
Пример #8
0
 def _mpl_repr(self):
     # how to represent ourselves to matplotlib
     return lib.ints_to_pydatetime(self.asi8)
Пример #9
0
 def _mpl_repr(self):
     # how to represent ourselves to matplotlib
     return lib.ints_to_pydatetime(self.asi8)
Пример #10
0
# <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
Пример #11
0
 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