Skip to content

Commit

Permalink
Add localize_datetime function
Browse files Browse the repository at this point in the history
  • Loading branch information
hsyyid committed Feb 9, 2024
1 parent 90019c8 commit 93e977c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
22 changes: 22 additions & 0 deletions gluestick/etl_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pandas as pd
import pyarrow.parquet as pq
from datetime import datetime
from pytz import utc
import ast
from gluestick.singer import to_singer

Expand Down Expand Up @@ -628,3 +629,24 @@ def get_types_from_catalog(self, catalog, stream):
dtype[col] = "object"

return dict(dtype=dtype, parse_dates=parse_dates)


def localize_datetime(df, column_name):
"""
Localize a Pandas DataFrame column to a specific timezone.
Parameters:
-----------
df : pandas.DataFrame
The DataFrame to be modified.
column_name : str
The name of the column to be localized.
"""
# Convert the column to a Pandas Timestamp object
df[column_name] = pd.to_datetime(df[column_name], errors="coerce")
# Localize the column to the specified timezone
try:
df[column_name] = df[column_name].dt.tz_localize(utc)
except:
df[column_name] = df[column_name].dt.tz_convert('UTC')

return df[column_name]
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name="gluestick",
version="2.1.10",
version="2.1.11",
description="ETL utility functions built on Pandas",
long_description=long_description,
long_description_content_type="text/markdown",
Expand All @@ -15,6 +15,7 @@
"numpy>=1.4",
"pandas>=1.2.5",
"pyarrow>=8.0.0",
"pytz>=2022.6"
],
author="hotglue",
author_email="[email protected]",
Expand Down

0 comments on commit 93e977c

Please sign in to comment.