Python numpy.datetime_data() Examples
The following are 26
code examples of numpy.datetime_data().
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
numpy
, or try the search function
.
Example #1
Source File: common.py From recruit with Apache License 2.0 | 6 votes |
def _validate_date_like_dtype(dtype): """ Check whether the dtype is a date-like dtype. Raises an error if invalid. Parameters ---------- dtype : dtype, type The dtype to check. Raises ------ TypeError : The dtype could not be casted to a date-like dtype. ValueError : The dtype is an illegal date-like dtype (e.g. the the frequency provided is too specific) """ try: typ = np.datetime_data(dtype)[0] except ValueError as e: raise TypeError('{error}'.format(error=e)) if typ != 'generic' and typ != 'ns': msg = '{name!r} is too specific of a frequency, try passing {type!r}' raise ValueError(msg.format(name=dtype.name, type=dtype.type.__name__))
Example #2
Source File: common.py From vnpy_crypto with MIT License | 6 votes |
def _validate_date_like_dtype(dtype): """ Check whether the dtype is a date-like dtype. Raises an error if invalid. Parameters ---------- dtype : dtype, type The dtype to check. Raises ------ TypeError : The dtype could not be casted to a date-like dtype. ValueError : The dtype is an illegal date-like dtype (e.g. the the frequency provided is too specific) """ try: typ = np.datetime_data(dtype)[0] except ValueError as e: raise TypeError('{error}'.format(error=e)) if typ != 'generic' and typ != 'ns': msg = '{name!r} is too specific of a frequency, try passing {type!r}' raise ValueError(msg.format(name=dtype.name, type=dtype.type.__name__))
Example #3
Source File: common.py From elasticintel with GNU General Public License v3.0 | 6 votes |
def _validate_date_like_dtype(dtype): """ Check whether the dtype is a date-like dtype. Raises an error if invalid. Parameters ---------- dtype : dtype, type The dtype to check. Raises ------ TypeError : The dtype could not be casted to a date-like dtype. ValueError : The dtype is an illegal date-like dtype (e.g. the the frequency provided is too specific) """ try: typ = np.datetime_data(dtype)[0] except ValueError as e: raise TypeError('{error}'.format(error=e)) if typ != 'generic' and typ != 'ns': msg = '{name!r} is too specific of a frequency, try passing {type!r}' raise ValueError(msg.format(name=dtype.name, type=dtype.type.__name__))
Example #4
Source File: common.py From Splunking-Crime with GNU Affero General Public License v3.0 | 6 votes |
def _validate_date_like_dtype(dtype): """ Check whether the dtype is a date-like dtype. Raises an error if invalid. Parameters ---------- dtype : dtype, type The dtype to check. Raises ------ TypeError : The dtype could not be casted to a date-like dtype. ValueError : The dtype is an illegal date-like dtype (e.g. the the frequency provided is too specific) """ try: typ = np.datetime_data(dtype)[0] except ValueError as e: raise TypeError('{error}'.format(error=e)) if typ != 'generic' and typ != 'ns': msg = '{name!r} is too specific of a frequency, try passing {type!r}' raise ValueError(msg.format(name=dtype.name, type=dtype.type.__name__))
Example #5
Source File: common.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def _validate_date_like_dtype(dtype): """ Check whether the dtype is a date-like dtype. Raises an error if invalid. Parameters ---------- dtype : dtype, type The dtype to check. Raises ------ TypeError : The dtype could not be casted to a date-like dtype. ValueError : The dtype is an illegal date-like dtype (e.g. the the frequency provided is too specific) """ try: typ = np.datetime_data(dtype)[0] except ValueError as e: raise TypeError('{error}'.format(error=e)) if typ != 'generic' and typ != 'ns': msg = '{name!r} is too specific of a frequency, try passing {type!r}' raise ValueError(msg.format(name=dtype.name, type=dtype.type.__name__))
Example #6
Source File: test_datetime.py From keras-lambda with MIT License | 5 votes |
def test_basic(self): a = np.array(['1980-03-23'], dtype=np.datetime64) assert_equal(np.datetime_data(a.dtype), ('D', 1))
Example #7
Source File: _dtype.py From recruit with Apache License 2.0 | 5 votes |
def _datetime_metadata_str(dtype): # TODO: this duplicates the C append_metastr_to_string unit, count = np.datetime_data(dtype) if unit == 'generic': return '' elif count == 1: return '[{}]'.format(unit) else: return '[{}{}]'.format(count, unit)
Example #8
Source File: test_datetime.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_basic(self): a = np.array(['1980-03-23'], dtype=np.datetime64) assert_equal(np.datetime_data(a.dtype), ('D', 1))
Example #9
Source File: test_datetime.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 5 votes |
def test_basic(self): a = np.array(['1980-03-23'], dtype=np.datetime64) assert_equal(np.datetime_data(a.dtype), ('D', 1))
Example #10
Source File: _dtype.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _datetime_metadata_str(dtype): # TODO: this duplicates the C append_metastr_to_string unit, count = np.datetime_data(dtype) if unit == 'generic': return '' elif count == 1: return '[{}]'.format(unit) else: return '[{}{}]'.format(count, unit)
Example #11
Source File: test_datetime.py From coffeegrindsize with MIT License | 5 votes |
def test_basic(self): a = np.array(['1980-03-23'], dtype=np.datetime64) assert_equal(np.datetime_data(a.dtype), ('D', 1))
Example #12
Source File: _dtype.py From coffeegrindsize with MIT License | 5 votes |
def _datetime_metadata_str(dtype): # TODO: this duplicates the C append_metastr_to_string unit, count = np.datetime_data(dtype) if unit == 'generic': return '' elif count == 1: return '[{}]'.format(unit) else: return '[{}{}]'.format(count, unit)
Example #13
Source File: test_datetime.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def test_basic(self): a = np.array(['1980-03-23'], dtype=np.datetime64) assert_equal(np.datetime_data(a.dtype), ('D', 1))
Example #14
Source File: test_datetime.py From ImageFusion with MIT License | 5 votes |
def test_basic(self): a = np.array(['1980-03-23'], dtype=np.datetime64) assert_equal(np.datetime_data(a.dtype), ('D', 1))
Example #15
Source File: test_datetime.py From mxnet-lambda with Apache License 2.0 | 5 votes |
def test_basic(self): a = np.array(['1980-03-23'], dtype=np.datetime64) assert_equal(np.datetime_data(a.dtype), ('D', 1))
Example #16
Source File: test_datetime.py From pySINDy with MIT License | 5 votes |
def test_basic(self): a = np.array(['1980-03-23'], dtype=np.datetime64) assert_equal(np.datetime_data(a.dtype), ('D', 1))
Example #17
Source File: test_datetime.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def test_basic(self): a = np.array(['1980-03-23'], dtype=np.datetime64) assert_equal(np.datetime_data(a.dtype), ('D', 1))
Example #18
Source File: _dtype.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
def _datetime_metadata_str(dtype): # TODO: this duplicates the C append_metastr_to_string unit, count = np.datetime_data(dtype) if unit == 'generic': return '' elif count == 1: return '[{}]'.format(unit) else: return '[{}{}]'.format(count, unit)
Example #19
Source File: test_datetime.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_basic(self): a = np.array(['1980-03-23'], dtype=np.datetime64) assert_equal(np.datetime_data(a.dtype), ('D', 1))
Example #20
Source File: test_datetime.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def test_basic(self): a = np.array(['1980-03-23'], dtype=np.datetime64) assert_equal(np.datetime_data(a.dtype), ('D', 1))
Example #21
Source File: _dtype.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def _datetime_metadata_str(dtype): # TODO: this duplicates the C append_metastr_to_string unit, count = np.datetime_data(dtype) if unit == 'generic': return '' elif count == 1: return '[{}]'.format(unit) else: return '[{}{}]'.format(count, unit)
Example #22
Source File: test_datetime.py From Computable with MIT License | 5 votes |
def test_basic(self): a = np.array(['1980-03-23'], dtype=np.datetime64) assert_equal(np.datetime_data(a.dtype), ('D', 1))
Example #23
Source File: test_datetime.py From vnpy_crypto with MIT License | 5 votes |
def test_basic(self): a = np.array(['1980-03-23'], dtype=np.datetime64) assert_equal(np.datetime_data(a.dtype), ('D', 1))
Example #24
Source File: test_datetime.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def test_basic(self): a = np.array(['1980-03-23'], dtype=np.datetime64) assert_equal(np.datetime_data(a.dtype), ('D', 1))
Example #25
Source File: test_datetime.py From recruit with Apache License 2.0 | 5 votes |
def test_basic(self): a = np.array(['1980-03-23'], dtype=np.datetime64) assert_equal(np.datetime_data(a.dtype), ('D', 1))
Example #26
Source File: features.py From torch-kalman with MIT License | 4 votes |
def fourier_model_mat(datetimes: np.ndarray, K: int, period: Union[np.timedelta64, str], output_fmt: str = 'float64') -> np.ndarray: """ :param datetimes: An array of datetimes. :param K: The expansion integer. :param period: Either a np.timedelta64, or one of {'weekly','yearly','daily'} :param start_datetime: A np.datetime64 on which to consider the season-start; useful for aligning (e.g) weekly seasons to start on Monday, or daily seasons to start on a particular hour. Default is first monday after epoch. :param output_fmt: A numpy dtype, or 'dataframe' to output a dataframe. :return: A numpy array (or dataframe) with the expanded fourier series. """ # parse period: name = 'fourier' if isinstance(period, str): name = period if period == 'weekly': period = np.timedelta64(7, 'D') elif period == 'yearly': period = np.timedelta64(int(365.25 * 24), 'h') elif period == 'daily': period = np.timedelta64(24, 'h') else: raise ValueError("Unrecognized `period`.") period_int = period.view('int64') dt_helper = DateTimeHelper(dt_unit=np.datetime_data(period)[0]) time = dt_helper.validate_datetimes(datetimes).view('int64') output_dataframe = (output_fmt.lower() == 'dataframe') if output_dataframe: output_fmt = 'float64' # fourier matrix: out_shape = tuple(datetimes.shape) + (K * 2,) out = np.empty(out_shape, dtype=output_fmt) columns = [] for idx in range(K): k = idx + 1 for is_cos in range(2): val = 2. * np.pi * k * time / period_int out[..., idx * 2 + is_cos] = np.sin(val) if is_cos == 0 else np.cos(val) columns.append(f"{name}_K{k}_{'cos' if is_cos else 'sin'}") if output_dataframe: if len(out_shape) > 2: raise ValueError("Cannot output dataframe when input is 2+D array.") from pandas import DataFrame out = DataFrame(out, columns=columns) return out