A package to provide tools to handle computations with datetime-like data.
Project description
Datetime Coordinates
This python package implements a feature allowing easy coding of datetime-like data without the annoyances of handling datetime-like data. Assim
It provides:
- high level function decorator
datetime_coords - lower level class
DateTimeCoordfor building other more customized decorators. - a marker
DatetimeLiketo indicate which data should be seen as datetime-like.
Installation
Within your python enviroment type
pip install dtcoords
Usage
This simplest way of using it is applying directly the decorator into a function wherein datetime-like data is been processed.
There is only a short protocol to be followed:
-
datetime-like parameters must be argument in a function (whether positional or keyword) and be typehinted with the special marker
DatetimeLikeprovided by the package. -
function must be defined as generic dictionary kws arguments or the special reserved keys:
_unit;_refor both.- valid units for
_unitparameter are the ones supported by numpy datetime dtype (numpy datetime units) _refshould be datetime-like and represents the "zeroth" location on the coordinates to which the data is been referenced under the hood.
- valid units for
-
As of now, nesting
DatetimelikeinSequenceor similar, won't do no good.
Quickstart
Let's have a basic function computing velocity as an average speed. The function should implement the following reasoning:
$$ v_{avg} = (x_2 - x_1) / (t_2 - t_1) $$
Start off by importing basic objects
from dtcoords import datetime_coords, DatetimeLike
They are meant to be used together.
@datetime_coords
def compute_average_seed(t1: DatetimeLike, x1: float, t2: DatetimeLike, x2: float, **kwargs) -> float:
delta_x = x2 - x1
delta t = t2 - t1
return delta_x / delta_t
Note that t1 and t2 are supposed to be datetime-like as a pandas Timestamp or the builtin python datetime,
nonetheless within the code they can be regarded as just common numeric data. Thus the code becomes more aligned
with how human brain thinks regarding time as quantity. So, regular operations are readily used and the return number is an ordinary float.
The function could then be called within a script as
import datetime
t1 = datetime.datetime(...)
t2 = datetime.datetime(...)
x1: float = ...
x2: float = ...
if x's are given in meters (for instance), then we are determinig our average speed in meters per seconds by requiring computation to be run with time unit in seconds s.
avg_speed = compute_average_speed(t1, x1, t2, x2, _unit='s')
autor: Conrado
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file datetimecoords-0.1.0.tar.gz.
File metadata
- Download URL: datetimecoords-0.1.0.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
640921214c60721567ecad03f1470ce3aae6e1027eebce017a571efc4dcef5f0
|
|
| MD5 |
bbb56ca1cbf5b811ac09a034d1a190f3
|
|
| BLAKE2b-256 |
f92939d50dbfb46815902131d4df371491532e8d97a23a3158f307465136e064
|
File details
Details for the file datetimecoords-0.1.0-py2.py3-none-any.whl.
File metadata
- Download URL: datetimecoords-0.1.0-py2.py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
990a1167a866bea61124aec573bb7682ce39ececaf39d53e07ee8493437aed82
|
|
| MD5 |
4089ff38569711902b863267c61f0c50
|
|
| BLAKE2b-256 |
9fc26810595f1179344cb3d99a214fae3098c0cd7a93daa0df86fc5b32b3b6ac
|