ts_shape.transform.time_functions.timezone_shift
¤
Classes:
-
TimezoneShift
–A class for shifting timestamps in a DataFrame to a different timezone, with methods to handle timezone localization and conversion.
TimezoneShift
¤
TimezoneShift(dataframe: DataFrame, column_name: str = 'systime')
Bases: Base
A class for shifting timestamps in a DataFrame to a different timezone, with methods to handle timezone localization and conversion.
Parameters:
-
dataframe
¤DataFrame
) –The DataFrame to be processed.
-
column_name
¤str
, default:'systime'
) –The column to sort by. Default is 'systime'. If the column is not found or is not a time column, the class will attempt to detect other time columns.
Methods:
-
add_timezone_column
–Creates a new column with timestamps converted from an input timezone to a target timezone, without altering the original column.
-
calculate_time_difference
–Calculates the time difference between two timestamp columns.
-
detect_timezone_awareness
–Detects if a time column in a DataFrame is timezone-aware.
-
get_dataframe
–Returns the processed DataFrame.
-
list_available_timezones
–Returns a list of all available timezones.
-
revert_to_original_timezone
–Reverts a timezone-shifted time column back to the original timezone.
-
shift_timezone
–Shifts timestamps in the specified column of a DataFrame from a given timezone to a target timezone.
Source code in src/ts_shape/utils/base.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
|
add_timezone_column
classmethod
¤
add_timezone_column(dataframe: DataFrame, time_column: str, input_timezone: str, target_timezone: str) -> DataFrame
Creates a new column with timestamps converted from an input timezone to a target timezone, without altering the original column.
Parameters:
-
dataframe
¤DataFrame
) –The DataFrame containing the data.
-
time_column
¤str
) –The name of the time column to convert.
-
input_timezone
¤str
) –The timezone of the input timestamps.
-
target_timezone
¤str
) –The target timezone.
Returns:
-
DataFrame
–pd.DataFrame: A DataFrame with an additional column for the shifted timezone.
Source code in src/ts_shape/transform/time_functions/timezone_shift.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
|
calculate_time_difference
classmethod
¤
calculate_time_difference(dataframe: DataFrame, start_column: str, end_column: str) -> Series
Calculates the time difference between two timestamp columns.
Parameters:
-
dataframe
¤DataFrame
) –The DataFrame containing the data.
-
start_column
¤str
) –The name of the start time column.
-
end_column
¤str
) –The name of the end time column.
Returns:
-
Series
–pd.Series: A Series with the time differences in seconds.
Source code in src/ts_shape/transform/time_functions/timezone_shift.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
|
detect_timezone_awareness
classmethod
¤
detect_timezone_awareness(dataframe: DataFrame, time_column: str) -> bool
Detects if a time column in a DataFrame is timezone-aware.
Parameters:
-
dataframe
¤DataFrame
) –The DataFrame containing the data.
-
time_column
¤str
) –The name of the time column to check.
Returns:
-
bool
(bool
) –True if the column is timezone-aware, False otherwise.
Source code in src/ts_shape/transform/time_functions/timezone_shift.py
83 84 85 86 87 88 89 90 91 92 93 94 95 |
|
get_dataframe
¤
get_dataframe() -> DataFrame
Returns the processed DataFrame.
Source code in src/ts_shape/utils/base.py
34 35 36 |
|
list_available_timezones
classmethod
¤
list_available_timezones() -> list
Returns a list of all available timezones.
Returns:
-
list
(list
) –A list of strings representing all available timezones.
Source code in src/ts_shape/transform/time_functions/timezone_shift.py
73 74 75 76 77 78 79 80 81 |
|
revert_to_original_timezone
classmethod
¤
revert_to_original_timezone(dataframe: DataFrame, time_column: str, original_timezone: str) -> DataFrame
Reverts a timezone-shifted time column back to the original timezone.
Parameters:
-
dataframe
¤DataFrame
) –The DataFrame containing the data.
-
time_column
¤str
) –The name of the time column to revert.
-
original_timezone
¤str
) –The original timezone to revert to.
Returns:
-
DataFrame
–pd.DataFrame: A DataFrame with timestamps reverted to the original timezone.
Source code in src/ts_shape/transform/time_functions/timezone_shift.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
|
shift_timezone
classmethod
¤
shift_timezone(dataframe: DataFrame, time_column: str, input_timezone: str, target_timezone: str) -> DataFrame
Shifts timestamps in the specified column of a DataFrame from a given timezone to a target timezone.
Parameters:
-
dataframe
¤DataFrame
) –The DataFrame containing the data.
-
time_column
¤str
) –The name of the time column to convert.
-
input_timezone
¤str
) –The timezone of the input timestamps (e.g., 'UTC' or 'America/New_York').
-
target_timezone
¤str
) –The target timezone to shift to (e.g., 'America/New_York').
Returns:
-
DataFrame
–pd.DataFrame: A DataFrame with timestamps converted to the target timezone.
Source code in src/ts_shape/transform/time_functions/timezone_shift.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
|