Python pandas.tseries.frequencies.get_to_timestamp_base() Examples

The following are 8 code examples of pandas.tseries.frequencies.get_to_timestamp_base(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pandas.tseries.frequencies , or try the search function .
Example #1
Source File: test_frequencies.py    From vnpy_crypto with MIT License 6 votes vote down vote up
def test_get_to_timestamp_base(self):
        tsb = frequencies.get_to_timestamp_base

        assert (tsb(frequencies.get_freq_code('D')[0]) ==
                frequencies.get_freq_code('D')[0])
        assert (tsb(frequencies.get_freq_code('W')[0]) ==
                frequencies.get_freq_code('D')[0])
        assert (tsb(frequencies.get_freq_code('M')[0]) ==
                frequencies.get_freq_code('D')[0])

        assert (tsb(frequencies.get_freq_code('S')[0]) ==
                frequencies.get_freq_code('S')[0])
        assert (tsb(frequencies.get_freq_code('T')[0]) ==
                frequencies.get_freq_code('S')[0])
        assert (tsb(frequencies.get_freq_code('H')[0]) ==
                frequencies.get_freq_code('S')[0]) 
Example #2
Source File: test_frequencies.py    From elasticintel with GNU General Public License v3.0 6 votes vote down vote up
def test_get_to_timestamp_base(self):
        tsb = frequencies.get_to_timestamp_base

        assert (tsb(frequencies.get_freq_code('D')[0]) ==
                frequencies.get_freq_code('D')[0])
        assert (tsb(frequencies.get_freq_code('W')[0]) ==
                frequencies.get_freq_code('D')[0])
        assert (tsb(frequencies.get_freq_code('M')[0]) ==
                frequencies.get_freq_code('D')[0])

        assert (tsb(frequencies.get_freq_code('S')[0]) ==
                frequencies.get_freq_code('S')[0])
        assert (tsb(frequencies.get_freq_code('T')[0]) ==
                frequencies.get_freq_code('S')[0])
        assert (tsb(frequencies.get_freq_code('H')[0]) ==
                frequencies.get_freq_code('S')[0]) 
Example #3
Source File: test_frequencies.py    From twitter-stock-recommendation with MIT License 6 votes vote down vote up
def test_get_to_timestamp_base(self):
        tsb = frequencies.get_to_timestamp_base

        assert (tsb(frequencies.get_freq_code('D')[0]) ==
                frequencies.get_freq_code('D')[0])
        assert (tsb(frequencies.get_freq_code('W')[0]) ==
                frequencies.get_freq_code('D')[0])
        assert (tsb(frequencies.get_freq_code('M')[0]) ==
                frequencies.get_freq_code('D')[0])

        assert (tsb(frequencies.get_freq_code('S')[0]) ==
                frequencies.get_freq_code('S')[0])
        assert (tsb(frequencies.get_freq_code('T')[0]) ==
                frequencies.get_freq_code('S')[0])
        assert (tsb(frequencies.get_freq_code('H')[0]) ==
                frequencies.get_freq_code('S')[0]) 
Example #4
Source File: period.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def to_timestamp(self, freq=None, how='start'):
        """
        Cast to DatetimeIndex

        Parameters
        ----------
        freq : string or DateOffset, optional
            Target frequency. The default is 'D' for week or longer,
            'S' otherwise
        how : {'s', 'e', 'start', 'end'}

        Returns
        -------
        DatetimeIndex
        """
        how = _validate_end_alias(how)

        if freq is None:
            base, mult = _gfc(self.freq)
            freq = frequencies.get_to_timestamp_base(base)
        else:
            freq = Period._maybe_convert_freq(freq)

        base, mult = _gfc(freq)
        new_data = self.asfreq(freq, how)

        new_data = period.periodarr_to_dt64arr(new_data._ndarray_values, base)
        return DatetimeIndex(new_data, freq='infer', name=self.name) 
Example #5
Source File: period.py    From Computable with MIT License 5 votes vote down vote up
def to_timestamp(self, freq=None, how='start', tz=None):
        """
        Return the Timestamp representation of the Period at the target
        frequency at the specified end (how) of the Period

        Parameters
        ----------
        freq : string or DateOffset, default is 'D' if self.freq is week or
               longer and 'S' otherwise
            Target frequency
        how: str, default 'S' (start)
            'S', 'E'. Can be aliased as case insensitive
            'Start', 'Finish', 'Begin', 'End'

        Returns
        -------
        Timestamp
        """
        how = _validate_end_alias(how)

        if freq is None:
            base, mult = _gfc(self.freq)
            freq = _freq_mod.get_to_timestamp_base(base)

        base, mult = _gfc(freq)
        val = self.asfreq(freq, how)

        dt64 = tslib.period_ordinal_to_dt64(val.ordinal, base)
        return Timestamp(dt64, tz=tz) 
Example #6
Source File: period.py    From Computable with MIT License 5 votes vote down vote up
def to_timestamp(self, freq=None, how='start'):
        """
        Cast to DatetimeIndex

        Parameters
        ----------
        freq : string or DateOffset, default 'D' for week or longer, 'S'
               otherwise
            Target frequency
        how : {'s', 'e', 'start', 'end'}

        Returns
        -------
        DatetimeIndex
        """
        how = _validate_end_alias(how)

        if freq is None:
            base, mult = _gfc(self.freq)
            freq = _freq_mod.get_to_timestamp_base(base)

        base, mult = _gfc(freq)
        new_data = self.asfreq(freq, how)

        new_data = tslib.periodarr_to_dt64arr(new_data.values, base)
        return DatetimeIndex(new_data, freq='infer', name=self.name) 
Example #7
Source File: period.py    From Splunking-Crime with GNU Affero General Public License v3.0 5 votes vote down vote up
def to_timestamp(self, freq=None, how='start'):
        """
        Cast to DatetimeIndex

        Parameters
        ----------
        freq : string or DateOffset, default 'D' for week or longer, 'S'
               otherwise
            Target frequency
        how : {'s', 'e', 'start', 'end'}

        Returns
        -------
        DatetimeIndex
        """
        how = _validate_end_alias(how)

        if freq is None:
            base, mult = _gfc(self.freq)
            freq = frequencies.get_to_timestamp_base(base)
        else:
            freq = Period._maybe_convert_freq(freq)

        base, mult = _gfc(freq)
        new_data = self.asfreq(freq, how)

        new_data = period.periodarr_to_dt64arr(new_data._values, base)
        return DatetimeIndex(new_data, freq='infer', name=self.name) 
Example #8
Source File: period.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def to_timestamp(self, freq=None, how='start'):
        """
        Cast to DatetimeIndex

        Parameters
        ----------
        freq : string or DateOffset, default 'D' for week or longer, 'S'
               otherwise
            Target frequency
        how : {'s', 'e', 'start', 'end'}

        Returns
        -------
        DatetimeIndex
        """
        how = _validate_end_alias(how)

        if freq is None:
            base, mult = _gfc(self.freq)
            freq = frequencies.get_to_timestamp_base(base)
        else:
            freq = Period._maybe_convert_freq(freq)

        base, mult = _gfc(freq)
        new_data = self.asfreq(freq, how)

        new_data = period.periodarr_to_dt64arr(new_data._values, base)
        return DatetimeIndex(new_data, freq='infer', name=self.name)