Skip to main content

Converts from onetime to another based on latatitude and longitude

Project description

Polars-Dates

Date routines for Polars.

  • ✅ blazingly fast, written in Rust!
  • ✅ seamless Polars integration!
  • ✅ Determine timezone string from latitude and longitudes!
  • ✅ Get localised date times based on the latitude and longitudes!
  • ✅ lookup timezones based on latitude / longitude

Installation

First, you need to install Polars.

Then, you'll need to install polars-dates:

pip install polars-dates

Usage

The module creates a custom namespace which is attached to a polars expression

What does this mean. If you are using polars regularly you will be aware of the .str and .arr (now renamed .list) namespaces which have special functions related to string and arrays / lists

This module creates a custom namespace

Basic Example

Say we start with a dataframe with 5 rows. This sample has 2 different places (Canary Wharf in London and New York). Using the Latitude and logitude we can lookup the timezone

The example below is useful since you will get autocomplete in the code editor

import polars as pl
import polars_dates as pl_dates
from datetime import datetime
df = (
    pl.DataFrame(data = {'lat' : [51.5054, 51.5054, 40.7128, 40.7128, 40.7128], 
                        'lon' : [0.0235, 0.0235, -74.0060, -74.0060, -74.0060],
                        'dt': [datetime(2024,1,24,9,0,0),
                                datetime(2024,1,24,9,0,0),
                                datetime(2024,1,24,9,0,0),
                                datetime(2024,1,24,3,0,0),
                                datetime(2024,1,24,3,0,0)],
                        'values' : [5,5,5,10,10]}
                )
    .with_columns(
         timezone = pl_dates.lookup_timezone(pl.col("lat"), pl.col("lon"))
    )
) 

Note you can also use the namespace. Which might help convay what is being done in a cleaner fashion

e.g. in the example below we will use the same test dataframe but convert the fields to a localised datetime

import polars as pl
import polars_dates as pl_dates
from datetime import datetime
df = (
    pl.DataFrame(data = {'lat' : [51.5054, 51.5054, 40.7128, 40.7128, 40.7128], 
                        'lon' : [0.0235, 0.0235, -74.0060, -74.0060, -74.0060],
                        'dt': [datetime(2024,1,24,9,0,0),
                                datetime(2024,1,24,9,0,0),
                                datetime(2024,1,24,9,0,0),
                                datetime(2024,1,24,3,0,0),
                                datetime(2024,1,24,3,0,0)],
                        'values' : [5,5,5,10,10]}
                )
    .with_columns(
         timezone_conv = pl.col("dt").dateconversions.to_local_in_new_timezone(pl.col("lat"), pl.col("lon"))
    )
)  

Note in the example we show how the dateconversions namespace is applied to the column dt.

This could also be written as

pl_dates.to_local_in_new_timezone(pl.col("dt"), pl.col("lat"), pl.col("lon"))

The exact form used will depend on personal preference and each has advantages and disadvantages.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

polars_geodates-0.19.12-cp311-cp311-manylinux_2_28_x86_64.whl (10.2 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.28+ x86-64

polars_geodates-0.19.12-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (10.2 MB view details)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

File details

Details for the file polars_geodates-0.19.12-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for polars_geodates-0.19.12-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ec898edfef34e006159a93cb9d9c369b68dcbe12cb461f1143274699c7de7adb
MD5 df7550c678c419829abf74257bc41c31
BLAKE2b-256 d622ab5514e9ddb58bd9e4c3a851bce1d781b73cce226945c838910974dfd098

See more details on using hashes here.

File details

Details for the file polars_geodates-0.19.12-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for polars_geodates-0.19.12-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d9382fc35f603dec466ef6c56c3092b687ed750a3d9f91d82bb3dc8d2b48b36e
MD5 a0265582231421328be376f86c08f4aa
BLAKE2b-256 8f938ef45490d4e67622df1e2c9d320cb136611ac09eeb8592c8781bcfd012f4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page