pygenutils 16.2.4__tar.gz → 16.3.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pygenutils-16.2.4/pygenutils.egg-info → pygenutils-16.3.1}/PKG-INFO +1 -1
- {pygenutils-16.2.4 → pygenutils-16.3.1}/pygenutils/__init__.py +1 -1
- {pygenutils-16.2.4 → pygenutils-16.3.1}/pygenutils/arrays_and_lists/data_manipulation.py +3 -3
- {pygenutils-16.2.4 → pygenutils-16.3.1}/pygenutils/arrays_and_lists/patterns.py +1 -1
- {pygenutils-16.2.4 → pygenutils-16.3.1}/pygenutils/audio_and_video/audio_and_video_manipulation.py +7 -7
- {pygenutils-16.2.4 → pygenutils-16.3.1}/pygenutils/audio_and_video/merge_audio_or_video.py +3 -3
- {pygenutils-16.2.4 → pygenutils-16.3.1}/pygenutils/audio_and_video/trim_media.py +3 -3
- {pygenutils-16.2.4 → pygenutils-16.3.1}/pygenutils/dictionaries/dict_operators.py +2 -2
- {pygenutils-16.2.4 → pygenutils-16.3.1}/pygenutils/number_bases/mathematical_utils.py +10 -10
- {pygenutils-16.2.4 → pygenutils-16.3.1}/pygenutils/operative_systems/os_operations.py +24 -24
- {pygenutils-16.2.4 → pygenutils-16.3.1}/pygenutils/sets_and_intervals/interval_handler.py +7 -6
- {pygenutils-16.2.4 → pygenutils-16.3.1}/pygenutils/sets_and_intervals/sets_handler.py +2 -2
- {pygenutils-16.2.4 → pygenutils-16.3.1}/pygenutils/time_handling/date_and_time_maths.py +18 -14
- {pygenutils-16.2.4 → pygenutils-16.3.1}/pygenutils/time_handling/program_snippet_exec_timers.py +21 -13
- {pygenutils-16.2.4 → pygenutils-16.3.1}/pygenutils/time_handling/time_formatters.py +94 -84
- {pygenutils-16.2.4 → pygenutils-16.3.1/pygenutils.egg-info}/PKG-INFO +1 -1
- {pygenutils-16.2.4 → pygenutils-16.3.1}/pyproject.toml +1 -1
- {pygenutils-16.2.4 → pygenutils-16.3.1}/LICENSE +0 -0
- {pygenutils-16.2.4 → pygenutils-16.3.1}/MANIFEST.in +0 -0
- {pygenutils-16.2.4 → pygenutils-16.3.1}/README.md +0 -0
- {pygenutils-16.2.4 → pygenutils-16.3.1}/pygenutils/arrays_and_lists/__init__.py +0 -0
- {pygenutils-16.2.4 → pygenutils-16.3.1}/pygenutils/arrays_and_lists/conversions.py +0 -0
- {pygenutils-16.2.4 → pygenutils-16.3.1}/pygenutils/arrays_and_lists/maths.py +0 -0
- {pygenutils-16.2.4 → pygenutils-16.3.1}/pygenutils/audio_and_video/__init__.py +0 -0
- {pygenutils-16.2.4 → pygenutils-16.3.1}/pygenutils/audio_and_video/merge_audio_and_video.py +0 -0
- {pygenutils-16.2.4 → pygenutils-16.3.1}/pygenutils/dictionaries/__init__.py +0 -0
- {pygenutils-16.2.4 → pygenutils-16.3.1}/pygenutils/dictionaries/dict_handler.py +0 -0
- {pygenutils-16.2.4 → pygenutils-16.3.1}/pygenutils/number_bases/__init__.py +0 -0
- {pygenutils-16.2.4 → pygenutils-16.3.1}/pygenutils/number_bases/base_converters.py +0 -0
- {pygenutils-16.2.4 → pygenutils-16.3.1}/pygenutils/number_bases/binary_operations.py +0 -0
- {pygenutils-16.2.4 → pygenutils-16.3.1}/pygenutils/number_bases/bitwise_operators.py +0 -0
- {pygenutils-16.2.4 → pygenutils-16.3.1}/pygenutils/operative_systems/__init__.py +0 -0
- {pygenutils-16.2.4 → pygenutils-16.3.1}/pygenutils/sets_and_intervals/__init__.py +0 -0
- {pygenutils-16.2.4 → pygenutils-16.3.1}/pygenutils/strings/__init__.py +0 -0
- {pygenutils-16.2.4 → pygenutils-16.3.1}/pygenutils/strings/string_handler.py +0 -0
- {pygenutils-16.2.4 → pygenutils-16.3.1}/pygenutils/strings/text_formatters.py +0 -0
- {pygenutils-16.2.4 → pygenutils-16.3.1}/pygenutils/time_handling/__init__.py +0 -0
- {pygenutils-16.2.4 → pygenutils-16.3.1}/pygenutils/time_handling/calendar_utils.py +0 -0
- {pygenutils-16.2.4 → pygenutils-16.3.1}/pygenutils/time_handling/countdown.py +0 -0
- {pygenutils-16.2.4 → pygenutils-16.3.1}/pygenutils/time_handling/date_and_time_utils.py +0 -0
- {pygenutils-16.2.4 → pygenutils-16.3.1}/pygenutils/time_handling/time_utils.py +0 -0
- {pygenutils-16.2.4 → pygenutils-16.3.1}/pygenutils.egg-info/SOURCES.txt +0 -0
- {pygenutils-16.2.4 → pygenutils-16.3.1}/pygenutils.egg-info/dependency_links.txt +0 -0
- {pygenutils-16.2.4 → pygenutils-16.3.1}/pygenutils.egg-info/requires.txt +0 -0
- {pygenutils-16.2.4 → pygenutils-16.3.1}/pygenutils.egg-info/top_level.txt +0 -0
- {pygenutils-16.2.4 → pygenutils-16.3.1}/setup.cfg +0 -0
- {pygenutils-16.2.4 → pygenutils-16.3.1}/setup.py +0 -0
|
@@ -165,7 +165,7 @@ def sort_1d_basic(arr, reverse=False):
|
|
|
165
165
|
elif isinstance(arr, list):
|
|
166
166
|
arr = flatten_list(arr)
|
|
167
167
|
|
|
168
|
-
#
|
|
168
|
+
# Program progression #
|
|
169
169
|
for i in range(len(arr)):
|
|
170
170
|
current = i
|
|
171
171
|
for k in range(i+1, len(arr)):
|
|
@@ -305,7 +305,7 @@ def revert_1d_basic(arr, procedure="index"):
|
|
|
305
305
|
elif isinstance(arr, list):
|
|
306
306
|
arr = flatten_list(arr)
|
|
307
307
|
|
|
308
|
-
#
|
|
308
|
+
# Program progression #
|
|
309
309
|
arr_len = len(arr)-1
|
|
310
310
|
if procedure == "iterative":
|
|
311
311
|
for i in range(arr_len//2):
|
|
@@ -593,7 +593,7 @@ def extract_1d_unique_basic(arr, procedure="dict", sort=False, reverse=False):
|
|
|
593
593
|
elif isinstance(arr, list):
|
|
594
594
|
arr = flatten_list(arr)
|
|
595
595
|
|
|
596
|
-
#
|
|
596
|
+
# Program progression #
|
|
597
597
|
if procedure == "dict":
|
|
598
598
|
unique_key_dict = dict.fromkeys(arr)
|
|
599
599
|
unique_val_arr = list(unique_key_dict.keys())
|
{pygenutils-16.2.4 → pygenutils-16.3.1}/pygenutils/audio_and_video/audio_and_video_manipulation.py
RENAMED
|
@@ -290,8 +290,8 @@ def merge_media_files(audio_files,
|
|
|
290
290
|
_validate_files(video_file_list, "Video file list (arg number 0)")
|
|
291
291
|
_validate_files(audio_file_list, "Audio file list (arg number 1)")
|
|
292
292
|
|
|
293
|
-
#
|
|
294
|
-
|
|
293
|
+
# Program progression #
|
|
294
|
+
#-#-#-#-#-#-#-#-#-#-#-#
|
|
295
295
|
|
|
296
296
|
# Generate default output file names if not provided
|
|
297
297
|
if output_file_list is None:
|
|
@@ -464,7 +464,7 @@ def merge_individual_media_files(media_inputs,
|
|
|
464
464
|
"""
|
|
465
465
|
|
|
466
466
|
# Validations #
|
|
467
|
-
|
|
467
|
+
#-#-#-#-#-#-#-#
|
|
468
468
|
|
|
469
469
|
# Audio bitrate fraction validation
|
|
470
470
|
if audio_bitrate_fraction is not None and (not isinstance(audio_bitrate_fraction, int) or audio_bitrate_fraction < 1):
|
|
@@ -506,8 +506,8 @@ def merge_individual_media_files(media_inputs,
|
|
|
506
506
|
raise ValueError("Input list contains both audio and video files. "
|
|
507
507
|
"Only one type is allowed.")
|
|
508
508
|
|
|
509
|
-
#
|
|
510
|
-
|
|
509
|
+
# Program progression #
|
|
510
|
+
#-#-#-#-#-#-#-#-#-#-#-#
|
|
511
511
|
|
|
512
512
|
# Generate default output file names if not provided #
|
|
513
513
|
if not output_file_name:
|
|
@@ -748,8 +748,8 @@ def cut_media_files(media_inputs,
|
|
|
748
748
|
if not isinstance(overwrite, bool):
|
|
749
749
|
raise ValueError("'overwrite' must be a boolean value.")
|
|
750
750
|
|
|
751
|
-
#
|
|
752
|
-
|
|
751
|
+
# Program progression #
|
|
752
|
+
#---------------------#
|
|
753
753
|
|
|
754
754
|
# If output file list is not provided, create default names
|
|
755
755
|
if output_file_list is None:
|
|
@@ -80,9 +80,9 @@ RETURN_OUTPUT_NAME = False
|
|
|
80
80
|
ENCODING = "utf-8"
|
|
81
81
|
SHELL = True
|
|
82
82
|
|
|
83
|
-
|
|
84
|
-
#
|
|
85
|
-
|
|
83
|
+
#---------------------#
|
|
84
|
+
# Program progression #
|
|
85
|
+
#---------------------#
|
|
86
86
|
|
|
87
87
|
merge_individual_media_files(
|
|
88
88
|
MEDIA_INPUT,
|
|
@@ -82,8 +82,8 @@ def dict_value_basic_operator(dict_list,
|
|
|
82
82
|
raise ValueError ("Invalid basic operator sign. "
|
|
83
83
|
f"Choose one from {list(ALLOWED_CALC_DICT.keys())}.")
|
|
84
84
|
|
|
85
|
-
#
|
|
86
|
-
|
|
85
|
+
# Program progression #
|
|
86
|
+
#-#-#-#-#-#-#-#-#-#-#-#
|
|
87
87
|
|
|
88
88
|
# Perform the computation #
|
|
89
89
|
operation = ALLOWED_CALC_DICT.get(math_operator)
|
|
@@ -6,11 +6,11 @@ from math import factorial
|
|
|
6
6
|
# Define functions #
|
|
7
7
|
#------------------#
|
|
8
8
|
|
|
9
|
-
def adapted_factorial(num,
|
|
9
|
+
def adapted_factorial(num, significant_digits):
|
|
10
10
|
"""
|
|
11
11
|
Calculate the factorial of a number with precise formatting control.
|
|
12
12
|
|
|
13
|
-
For standard-sized results, formats the output using the specified
|
|
13
|
+
For standard-sized results, formats the output using the specified precision.
|
|
14
14
|
For extremely large factorials that would cause an OverflowError during formatting,
|
|
15
15
|
converts the result to scientific notation with appropriate rounding.
|
|
16
16
|
|
|
@@ -18,7 +18,7 @@ def adapted_factorial(num, decimals):
|
|
|
18
18
|
----------
|
|
19
19
|
num : int | float
|
|
20
20
|
The number for which to calculate the factorial
|
|
21
|
-
|
|
21
|
+
significant_digits : int
|
|
22
22
|
The number of significant digits to include in the result
|
|
23
23
|
|
|
24
24
|
Returns
|
|
@@ -40,17 +40,17 @@ def adapted_factorial(num, decimals):
|
|
|
40
40
|
result = factorial(num)
|
|
41
41
|
|
|
42
42
|
try:
|
|
43
|
-
result = f"{result:.{
|
|
43
|
+
result = f"{result:.{significant_digits}g}"
|
|
44
44
|
except OverflowError:
|
|
45
|
-
# Convert to string and round to the desired
|
|
45
|
+
# Convert to string and round to the desired significant digits
|
|
46
46
|
result_str = str(result)
|
|
47
|
-
# Take into account the number next to the
|
|
48
|
-
if int(result_str[
|
|
49
|
-
prev_num = int(result_str[
|
|
47
|
+
# Take into account the number next to the significant digits position
|
|
48
|
+
if int(result_str[significant_digits]) >= 5:
|
|
49
|
+
prev_num = int(result_str[significant_digits-1]) + 1
|
|
50
50
|
else:
|
|
51
|
-
prev_num = int(result_str[
|
|
51
|
+
prev_num = int(result_str[significant_digits-1])
|
|
52
52
|
# Convert to float
|
|
53
|
-
result_adapted = f"{result_str[0]}.{result_str[1:
|
|
53
|
+
result_adapted = f"{result_str[0]}.{result_str[1:significant_digits-1]}{prev_num}e+{len(result_str)-1}"
|
|
54
54
|
else:
|
|
55
55
|
result_adapted = result
|
|
56
56
|
|
|
@@ -139,7 +139,7 @@ def os_system_helper(command, capture_output):
|
|
|
139
139
|
"""
|
|
140
140
|
|
|
141
141
|
# Validations #
|
|
142
|
-
|
|
142
|
+
#-#-#-#-#-#-#-#
|
|
143
143
|
|
|
144
144
|
# Command and class #
|
|
145
145
|
if not isinstance(command, str):
|
|
@@ -150,8 +150,8 @@ def os_system_helper(command, capture_output):
|
|
|
150
150
|
if capture_output:
|
|
151
151
|
raise ValueError("os.system cannot capture output.")
|
|
152
152
|
|
|
153
|
-
#
|
|
154
|
-
|
|
153
|
+
# Program progression #
|
|
154
|
+
#-#-#-#-#-#-#-#-#-#-#-#
|
|
155
155
|
|
|
156
156
|
# Execute the command
|
|
157
157
|
exit_code = os.system(command)
|
|
@@ -180,7 +180,7 @@ def os_popen_helper(command, capture_output):
|
|
|
180
180
|
"""
|
|
181
181
|
|
|
182
182
|
# Validations #
|
|
183
|
-
|
|
183
|
+
#-#-#-#-#-#-#-#
|
|
184
184
|
|
|
185
185
|
# Command and class #
|
|
186
186
|
if not isinstance(command, str):
|
|
@@ -191,8 +191,8 @@ def os_popen_helper(command, capture_output):
|
|
|
191
191
|
if not capture_output:
|
|
192
192
|
raise ValueError("os.popen must capture output.")
|
|
193
193
|
|
|
194
|
-
#
|
|
195
|
-
|
|
194
|
+
# Program progression #
|
|
195
|
+
#-#-#-#-#-#-#-#-#-#-#-#
|
|
196
196
|
|
|
197
197
|
# Capture the output
|
|
198
198
|
output = os.popen(command).read()
|
|
@@ -231,26 +231,26 @@ def subprocess_popen_helper(command, capture_output, encoding, return_output_nam
|
|
|
231
231
|
"""
|
|
232
232
|
from subprocess import Popen, PIPE
|
|
233
233
|
|
|
234
|
-
# Set text parameter (if not provided, use encoding as a fallback)
|
|
234
|
+
# Set text parameter (if not provided, use encoding as a fallback) #
|
|
235
235
|
text_param = text if text is not None else bool(encoding)
|
|
236
236
|
|
|
237
|
-
# Define the I/O streams
|
|
237
|
+
# Define the I/O streams #
|
|
238
238
|
pipe_kwargs = dict(stdin=PIPE, stdout=PIPE, stderr=PIPE) if capture_output else {}
|
|
239
239
|
|
|
240
|
-
# Execute the command
|
|
240
|
+
# Execute the command #
|
|
241
241
|
process = Popen(command, **pipe_kwargs, text=text_param)
|
|
242
242
|
|
|
243
|
-
# Wait for command to complete
|
|
243
|
+
# Wait for command to complete #
|
|
244
244
|
process.wait()
|
|
245
245
|
|
|
246
|
-
# Initialise return dictionary with return code
|
|
246
|
+
# Initialise return dictionary with return code #
|
|
247
247
|
return_dict = {"return_code": process.returncode}
|
|
248
248
|
|
|
249
|
-
# Add errors if available
|
|
249
|
+
# Add errors if available #
|
|
250
250
|
if hasattr(process, "errors"):
|
|
251
251
|
return_dict["errors"] = process.errors
|
|
252
252
|
|
|
253
|
-
# Only capture stdin, stdout, stderr if output capturing was requested
|
|
253
|
+
# Only capture stdin, stdout, stderr if output capturing was requested #
|
|
254
254
|
if capture_output:
|
|
255
255
|
if return_output_name:
|
|
256
256
|
# Return file descriptor names
|
|
@@ -281,7 +281,7 @@ def subprocess_popen_helper(command, capture_output, encoding, return_output_nam
|
|
|
281
281
|
else:
|
|
282
282
|
return_dict["stderr"] = process.stderr.read().decode(encoding) if encoding else process.stderr.read()
|
|
283
283
|
|
|
284
|
-
# Return the compiled result dictionary
|
|
284
|
+
# Return the compiled result dictionary #
|
|
285
285
|
return return_dict
|
|
286
286
|
|
|
287
287
|
|
|
@@ -351,16 +351,16 @@ def subprocess_run_helper(command, capture_output, encoding, shell, text):
|
|
|
351
351
|
"""
|
|
352
352
|
from subprocess import run
|
|
353
353
|
|
|
354
|
-
# Set text parameter (if not provided, use encoding as a fallback)
|
|
354
|
+
# Set text parameter (if not provided, use encoding as a fallback) #
|
|
355
355
|
text_param = text if text is not None else bool(encoding)
|
|
356
356
|
|
|
357
|
-
# Execute the command and capture output if requested
|
|
357
|
+
# Execute the command and capture output if requested #
|
|
358
358
|
result = run(command, capture_output=capture_output, text=text_param, shell=shell)
|
|
359
359
|
|
|
360
|
-
# Initialise return dictionary with return code
|
|
360
|
+
# Initialise return dictionary with return code #
|
|
361
361
|
return_dict = {"return_code": result.returncode}
|
|
362
362
|
|
|
363
|
-
# Only process stdout/stderr if they were captured
|
|
363
|
+
# Only process stdout/stderr if they were captured #
|
|
364
364
|
if capture_output:
|
|
365
365
|
# Add stdout and stderr to the return dictionary if available
|
|
366
366
|
if hasattr(result, "stdout"):
|
|
@@ -430,10 +430,10 @@ def exit_info(process_exit_info_obj, check_stdout=True, check_stderr=True, check
|
|
|
430
430
|
raise RuntimeError("Command string interpreted as a path. "
|
|
431
431
|
"Please check the command.")
|
|
432
432
|
else:
|
|
433
|
-
# Check if we're dealing with a dictionary or a CompletedProcess object
|
|
433
|
+
# Check if we're dealing with a dictionary or a CompletedProcess object #
|
|
434
434
|
is_dict = isinstance(process_exit_info_obj, dict)
|
|
435
435
|
|
|
436
|
-
# Get return code - handle both dict and CompletedProcess objects
|
|
436
|
+
# Get return code - handle both dict and CompletedProcess objects #
|
|
437
437
|
if is_dict:
|
|
438
438
|
return_code = process_exit_info_obj.get("return_code")
|
|
439
439
|
# Check if we have any output information
|
|
@@ -446,7 +446,7 @@ def exit_info(process_exit_info_obj, check_stdout=True, check_stderr=True, check
|
|
|
446
446
|
has_stdout = hasattr(process_exit_info_obj, "stdout")
|
|
447
447
|
has_stderr = hasattr(process_exit_info_obj, "stderr")
|
|
448
448
|
|
|
449
|
-
# Print stdout if available and requested
|
|
449
|
+
# Print stdout if available and requested #
|
|
450
450
|
if check_stdout:
|
|
451
451
|
if is_dict and has_stdout and process_exit_info_obj.get("stdout"):
|
|
452
452
|
print(f"STDOUT\n{'='*6}")
|
|
@@ -455,7 +455,7 @@ def exit_info(process_exit_info_obj, check_stdout=True, check_stderr=True, check
|
|
|
455
455
|
print(f"STDOUT\n{'='*6}")
|
|
456
456
|
print(process_exit_info_obj.stdout)
|
|
457
457
|
|
|
458
|
-
# Print stderr if available and requested
|
|
458
|
+
# Print stderr if available and requested #
|
|
459
459
|
if check_stderr:
|
|
460
460
|
if is_dict and has_stderr and process_exit_info_obj.get("stderr"):
|
|
461
461
|
print(f"STDERR\n{'='*6}")
|
|
@@ -464,7 +464,7 @@ def exit_info(process_exit_info_obj, check_stdout=True, check_stderr=True, check
|
|
|
464
464
|
print(f"STDERR\n{'='*6}")
|
|
465
465
|
print(process_exit_info_obj.stderr)
|
|
466
466
|
|
|
467
|
-
# Check return code if requested
|
|
467
|
+
# Check return code if requested #
|
|
468
468
|
if check_return_code:
|
|
469
469
|
if return_code == 0:
|
|
470
470
|
print("Process completed successfully with return code 0")
|
|
@@ -482,7 +482,7 @@ def exit_info(process_exit_info_obj, check_stdout=True, check_stderr=True, check
|
|
|
482
482
|
raise RuntimeError("An error occurred during command execution: "
|
|
483
483
|
f"{format_string(NONZERO_EXIT_STATUS_TEMPLATE, format_args_error)}")
|
|
484
484
|
|
|
485
|
-
# If return code checking is disabled, just return True
|
|
485
|
+
# If return code checking is disabled, just return True #
|
|
486
486
|
return True
|
|
487
487
|
|
|
488
488
|
# %%
|
|
@@ -104,11 +104,12 @@ def define_interval(left_limit, right_limit, constructor="pandas", closed="both"
|
|
|
104
104
|
"""
|
|
105
105
|
|
|
106
106
|
# Input validation #
|
|
107
|
-
|
|
107
|
+
#-#-#-#-#-#-#-#-#-#-
|
|
108
|
+
|
|
108
109
|
_validate_interval_parameters(left_limit, right_limit, constructor, closed)
|
|
109
110
|
|
|
110
|
-
#
|
|
111
|
-
|
|
111
|
+
# Program progression #
|
|
112
|
+
#-#-#-#-#-#-#-#-#-#-#-#
|
|
112
113
|
|
|
113
114
|
if constructor == "intervaltree":
|
|
114
115
|
print(f"WARNING: intervals constructed using constructor '{constructor}' "
|
|
@@ -167,7 +168,7 @@ def basic_interval_operator(interval_array,
|
|
|
167
168
|
"""
|
|
168
169
|
|
|
169
170
|
# Input validation #
|
|
170
|
-
|
|
171
|
+
#-#-#-#-#-#-#-#-#-#-
|
|
171
172
|
|
|
172
173
|
particular_constructor_opts = INTERVAL_CONSTRUCTOR_OPTIONS[:2]
|
|
173
174
|
all_args = get_caller_args()
|
|
@@ -187,8 +188,8 @@ def basic_interval_operator(interval_array,
|
|
|
187
188
|
if isinstance(interval_array, list) and any(isinstance(item, list) for item in interval_array):
|
|
188
189
|
interval_array = flatten_list(interval_array)
|
|
189
190
|
|
|
190
|
-
#
|
|
191
|
-
|
|
191
|
+
# Program progression #
|
|
192
|
+
#-#-#-#-#-#-#-#-#-#-#-#
|
|
192
193
|
|
|
193
194
|
try:
|
|
194
195
|
if constructor == "pandas" and operator == "union" and force_union:
|
|
@@ -67,8 +67,8 @@ def sets_operator(array_of_sets1,
|
|
|
67
67
|
if array_of_sets2 is not None and isinstance(array_of_sets2, list) and any(isinstance(item, list) for item in array_of_sets2):
|
|
68
68
|
array_of_sets2 = flatten_list(array_of_sets2)
|
|
69
69
|
|
|
70
|
-
#
|
|
71
|
-
|
|
70
|
+
# Program progression #
|
|
71
|
+
#-#-#-#-#-#-#-#-#-#-#-#
|
|
72
72
|
|
|
73
73
|
if constructor == "default":
|
|
74
74
|
if operator == "cartesian_product":
|
|
@@ -80,9 +80,11 @@ def _validate_option(arg_iterable, error_class, error_str):
|
|
|
80
80
|
#-------#
|
|
81
81
|
|
|
82
82
|
# Sum and subtract operations #
|
|
83
|
-
|
|
83
|
+
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
|
|
84
84
|
|
|
85
85
|
# Main method #
|
|
86
|
+
#-#-#-#-#-#-#-#
|
|
87
|
+
|
|
86
88
|
def sum_dt_objects(dt_obj_list,
|
|
87
89
|
dt_fmt_str="%T",
|
|
88
90
|
operation="sum",
|
|
@@ -151,8 +153,8 @@ def sum_dt_objects(dt_obj_list,
|
|
|
151
153
|
arg_iterable_output_format = (output_format, TIME_OUTPUT_FORMAT_OPTIONS)
|
|
152
154
|
_validate_option(arg_iterable_output_format, ValueError, INVALID_OUTPUT_FORMAT_TEMPLATE)
|
|
153
155
|
|
|
154
|
-
#
|
|
155
|
-
|
|
156
|
+
# Program progression #
|
|
157
|
+
#######################
|
|
156
158
|
|
|
157
159
|
# Time delta object conversions #
|
|
158
160
|
timedelta_list = []
|
|
@@ -171,6 +173,8 @@ def sum_dt_objects(dt_obj_list,
|
|
|
171
173
|
|
|
172
174
|
|
|
173
175
|
# Auxiliary methods #
|
|
176
|
+
#-#-#-#-#-#-#-#-#-#-#
|
|
177
|
+
|
|
174
178
|
def extract_dt_part(datetime_obj, part="time", arg_list=None):
|
|
175
179
|
"""
|
|
176
180
|
Return the time or date part of a datetime object.
|
|
@@ -205,13 +209,13 @@ def extract_dt_part(datetime_obj, part="time", arg_list=None):
|
|
|
205
209
|
|
|
206
210
|
|
|
207
211
|
# Time average #
|
|
208
|
-
|
|
212
|
+
#~~~~~~~~~~~~~~#
|
|
209
213
|
|
|
210
214
|
# Adapted from https://stackoverflow.com/questions/12033905/using-python-to-create-an-average-out-of-a-list-of-times
|
|
211
215
|
# and refined with ChatGPT
|
|
212
216
|
|
|
213
217
|
# Main method #
|
|
214
|
-
|
|
218
|
+
#-#-#-#-#-#-#-#
|
|
215
219
|
|
|
216
220
|
def dt_average(dt_obj_list,
|
|
217
221
|
time_fmt_str="%T",
|
|
@@ -270,8 +274,8 @@ def dt_average(dt_obj_list,
|
|
|
270
274
|
arg_iterable_output_format = (output_format, TIME_OUTPUT_FORMAT_OPTIONS)
|
|
271
275
|
_validate_option(arg_iterable_output_format, ValueError, INVALID_OUTPUT_FORMAT_TEMPLATE)
|
|
272
276
|
|
|
273
|
-
#
|
|
274
|
-
|
|
277
|
+
# Program progression #
|
|
278
|
+
#######################
|
|
275
279
|
|
|
276
280
|
angles = [_dt_to_radians(dt_obj, "datetime", time_fmt_str) for dt_obj in dt_obj_list]
|
|
277
281
|
avg_angle = _average_angle(angles)
|
|
@@ -283,7 +287,7 @@ def dt_average(dt_obj_list,
|
|
|
283
287
|
|
|
284
288
|
|
|
285
289
|
# Auxiliary methods #
|
|
286
|
-
|
|
290
|
+
#-#-#-#-#-#-#-#-#-#-#
|
|
287
291
|
|
|
288
292
|
def _dt_to_radians(t, convert_to="datetime", time_fmt_str=None):
|
|
289
293
|
"""
|
|
@@ -401,7 +405,7 @@ def _radians_to_time_of_day(rads):
|
|
|
401
405
|
#-------#
|
|
402
406
|
|
|
403
407
|
# Sum and subtract operations #
|
|
404
|
-
|
|
408
|
+
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
|
|
405
409
|
|
|
406
410
|
def sum_date_objects(date_list,
|
|
407
411
|
operation="sum",
|
|
@@ -465,8 +469,8 @@ def sum_date_objects(date_list,
|
|
|
465
469
|
arg_iterable_output_format = (output_format, TIME_OUTPUT_FORMAT_OPTIONS)
|
|
466
470
|
_validate_option(arg_iterable_output_format, ValueError, INVALID_OUTPUT_FORMAT_TEMPLATE)
|
|
467
471
|
|
|
468
|
-
#
|
|
469
|
-
|
|
472
|
+
# Program progression #
|
|
473
|
+
#######################
|
|
470
474
|
|
|
471
475
|
# Perform the aritmethical operations #
|
|
472
476
|
total_date = parse_dt_string(date_list[0], dt_fmt_str)
|
|
@@ -582,7 +586,7 @@ def _add_dates_with_year_gap(date1, date2, operation):
|
|
|
582
586
|
|
|
583
587
|
|
|
584
588
|
# Natural years #
|
|
585
|
-
|
|
589
|
+
#~~~~~~~~~~~~~~#
|
|
586
590
|
|
|
587
591
|
def natural_year(dt_start, dt_end, dt_fmt_str=None,
|
|
588
592
|
method="pandas",
|
|
@@ -641,8 +645,8 @@ def natural_year(dt_start, dt_end, dt_fmt_str=None,
|
|
|
641
645
|
"must be a boolean.")
|
|
642
646
|
|
|
643
647
|
|
|
644
|
-
#
|
|
645
|
-
|
|
648
|
+
# Program progression #
|
|
649
|
+
#·#·#·#·#·#·#·#·#·#·#·#
|
|
646
650
|
|
|
647
651
|
# Convert input objects to datetime objects #
|
|
648
652
|
#############################################
|
{pygenutils-16.2.4 → pygenutils-16.3.1}/pygenutils/time_handling/program_snippet_exec_timers.py
RENAMED
|
@@ -102,7 +102,7 @@ def program_exec_timer(mode, module="time", frac_precision=3):
|
|
|
102
102
|
global ti
|
|
103
103
|
|
|
104
104
|
# Input validations #
|
|
105
|
-
|
|
105
|
+
#-#-#-#-#-#-#-#-#-#-#
|
|
106
106
|
|
|
107
107
|
# Module #
|
|
108
108
|
_validate_option("Module", module, MODULE_LIST)
|
|
@@ -110,8 +110,8 @@ def program_exec_timer(mode, module="time", frac_precision=3):
|
|
|
110
110
|
# Fractional second precision #
|
|
111
111
|
_validate_precision(frac_precision, max_prec=6)
|
|
112
112
|
|
|
113
|
-
#
|
|
114
|
-
|
|
113
|
+
# Program progression #
|
|
114
|
+
#-#-#-#-#-#-#-#-#-#-#-#
|
|
115
115
|
|
|
116
116
|
if mode == "start":
|
|
117
117
|
ti = MODULE_OPERATION_DICT[module]()
|
|
@@ -135,25 +135,31 @@ def program_exec_timer(mode, module="time", frac_precision=3):
|
|
|
135
135
|
def snippet_exec_timer(snippet_str,
|
|
136
136
|
repeats=None,
|
|
137
137
|
trials=int(1e4),
|
|
138
|
-
|
|
138
|
+
decimal_places=None,
|
|
139
139
|
format_time_str=False,
|
|
140
140
|
return_best_time=False):
|
|
141
141
|
|
|
142
|
-
#
|
|
142
|
+
# Decimal places validation #
|
|
143
|
+
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
|
|
144
|
+
|
|
143
145
|
param_keys = get_caller_args()
|
|
144
|
-
|
|
146
|
+
decimal_places_arg_pos = find_substring_index(param_keys, "decimal_places")
|
|
145
147
|
|
|
146
|
-
if not isinstance(
|
|
147
|
-
raise TypeError(format_string(TYPE_ERROR_TEMPLATE, f'{param_keys[
|
|
148
|
+
if not isinstance(decimal_places, int):
|
|
149
|
+
raise TypeError(format_string(TYPE_ERROR_TEMPLATE, f'{param_keys[decimal_places_arg_pos]}'))
|
|
148
150
|
|
|
149
151
|
# Set keyword argument dictionary for float time parsing #
|
|
152
|
+
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-
|
|
153
|
+
|
|
150
154
|
float_time_parsing_kwargs = dict(
|
|
151
155
|
module="str",
|
|
152
156
|
origin="arbitrary",
|
|
153
|
-
frac_precision=
|
|
157
|
+
frac_precision=decimal_places
|
|
154
158
|
)
|
|
155
159
|
|
|
156
160
|
# Execution time in the specified number of trials with no repeats #
|
|
161
|
+
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-
|
|
162
|
+
|
|
157
163
|
if repeats is None:
|
|
158
164
|
exec_time_norep = timeit.timeit(setup=snippet_str,
|
|
159
165
|
number=trials,
|
|
@@ -164,8 +170,8 @@ def snippet_exec_timer(snippet_str,
|
|
|
164
170
|
exec_time_norep = timeit.repeat(snippet_str, repeat=1, number=10000)[0]
|
|
165
171
|
"""
|
|
166
172
|
|
|
167
|
-
if
|
|
168
|
-
exec_time_norep = np_round(exec_time_norep,
|
|
173
|
+
if decimal_places is not None:
|
|
174
|
+
exec_time_norep = np_round(exec_time_norep, decimal_places)
|
|
169
175
|
|
|
170
176
|
if not format_time_str:
|
|
171
177
|
time_unit_str = SEC_TIME_UNIT_STR
|
|
@@ -178,14 +184,16 @@ def snippet_exec_timer(snippet_str,
|
|
|
178
184
|
print_format_string(NOREP_EXEC_TIME_INFO_TEMPLATE, format_args_exec_timer1)
|
|
179
185
|
|
|
180
186
|
# Execution time in the specified number of trials for several repeats #
|
|
187
|
+
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-
|
|
188
|
+
|
|
181
189
|
else:
|
|
182
190
|
exec_time_rep = timeit.repeat(setup=snippet_str,
|
|
183
191
|
repeat=repeats,
|
|
184
192
|
number=trials,
|
|
185
193
|
globals=globals())
|
|
186
194
|
|
|
187
|
-
if
|
|
188
|
-
exec_time_rep = np_round(exec_time_rep,
|
|
195
|
+
if decimal_places is not None:
|
|
196
|
+
exec_time_rep = np_round(exec_time_rep, decimal_places)
|
|
189
197
|
|
|
190
198
|
# Compute best time
|
|
191
199
|
best_time = min(exec_time_rep)
|
|
@@ -7,12 +7,12 @@
|
|
|
7
7
|
|
|
8
8
|
# Standard modules #
|
|
9
9
|
import time
|
|
10
|
-
from datetime import datetime
|
|
10
|
+
from datetime import datetime, timedelta
|
|
11
11
|
|
|
12
12
|
# Third-party modules #
|
|
13
13
|
import numpy as np
|
|
14
14
|
import pandas as pd
|
|
15
|
-
from dateutil import
|
|
15
|
+
from dateutil.parser import parse
|
|
16
16
|
|
|
17
17
|
#------------------------#
|
|
18
18
|
# Import project modules #
|
|
@@ -204,7 +204,7 @@ def parse_dt_string(datetime_str, dt_fmt_str=None, module="datetime", unit="ns",
|
|
|
204
204
|
"""
|
|
205
205
|
|
|
206
206
|
# Input validation #
|
|
207
|
-
|
|
207
|
+
#-#-#-#-#-#-#-#-#-#-
|
|
208
208
|
|
|
209
209
|
# Module #
|
|
210
210
|
allowed_modules = list(TIME_STR_PARSING_DICT.keys())
|
|
@@ -215,7 +215,7 @@ def parse_dt_string(datetime_str, dt_fmt_str=None, module="datetime", unit="ns",
|
|
|
215
215
|
raise ValueError("A datetime format string must be provided for non-pandas modules.")
|
|
216
216
|
|
|
217
217
|
# Time string parsing #
|
|
218
|
-
|
|
218
|
+
#-#-#-#-#-#-#-#-#-#-#-#
|
|
219
219
|
|
|
220
220
|
try:
|
|
221
221
|
parse_func = TIME_STR_PARSING_DICT.get(module)
|
|
@@ -245,7 +245,7 @@ def parse_dt_string(datetime_str, dt_fmt_str=None, module="datetime", unit="ns",
|
|
|
245
245
|
#--------------------------#
|
|
246
246
|
|
|
247
247
|
# Main function #
|
|
248
|
-
|
|
248
|
+
#~~~~~~~~~~~~~~~#
|
|
249
249
|
|
|
250
250
|
def parse_float_dt(datetime_float,
|
|
251
251
|
frac_precision=None,
|
|
@@ -308,14 +308,14 @@ def parse_float_dt(datetime_float,
|
|
|
308
308
|
"""
|
|
309
309
|
|
|
310
310
|
# Input validation #
|
|
311
|
-
|
|
311
|
+
#-#-#-#-#-#-#-#-#-#-
|
|
312
312
|
|
|
313
313
|
# Module #
|
|
314
314
|
allowed_modules = ["str"] + list(FLOATED_TIME_PARSING_DICT.keys())
|
|
315
315
|
_validate_option("Object type conversion", module, allowed_modules)
|
|
316
316
|
|
|
317
317
|
# Time formatting string #
|
|
318
|
-
if module
|
|
318
|
+
if module == "str" and not dt_fmt_str:
|
|
319
319
|
raise ValueError("You must provide a formatting string.")
|
|
320
320
|
|
|
321
321
|
# Fractional second precision #
|
|
@@ -325,7 +325,7 @@ def parse_float_dt(datetime_float,
|
|
|
325
325
|
_validate_unit(unit, module)
|
|
326
326
|
|
|
327
327
|
# Floated time parsing #
|
|
328
|
-
|
|
328
|
+
#-#-#-#-#-#-#-#-#-#-#-#-
|
|
329
329
|
|
|
330
330
|
if module == "str":
|
|
331
331
|
return _parse_float_to_string(datetime_float,
|
|
@@ -341,7 +341,7 @@ def parse_float_dt(datetime_float,
|
|
|
341
341
|
|
|
342
342
|
|
|
343
343
|
# Auxiliary functions #
|
|
344
|
-
|
|
344
|
+
#~~~~~~~~~~~~~~~~~~~~~#
|
|
345
345
|
|
|
346
346
|
def _parse_float_to_string(floated_time,
|
|
347
347
|
frac_precision,
|
|
@@ -433,7 +433,7 @@ def _float_dt_parser(floated_time, module, unit, dayfirst, yearfirst):
|
|
|
433
433
|
"""
|
|
434
434
|
|
|
435
435
|
# Input validation #
|
|
436
|
-
|
|
436
|
+
#-#-#-#-#-#-#-#-#-#-
|
|
437
437
|
|
|
438
438
|
# Module #
|
|
439
439
|
allowed_modules = list(FLOATED_TIME_PARSING_DICT.keys())
|
|
@@ -443,7 +443,7 @@ def _float_dt_parser(floated_time, module, unit, dayfirst, yearfirst):
|
|
|
443
443
|
_validate_unit(unit, module)
|
|
444
444
|
|
|
445
445
|
# Calculate datetime object #
|
|
446
|
-
|
|
446
|
+
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#
|
|
447
447
|
|
|
448
448
|
datetime_obj = FLOATED_TIME_PARSING_DICT.get(module)(floated_time, unit, dayfirst, yearfirst)
|
|
449
449
|
return datetime_obj
|
|
@@ -514,19 +514,19 @@ def _format_arbitrary_dt(floated_time, frac_precision):
|
|
|
514
514
|
# %% PARSING AMONG COMPLEX DATA OBJECTS
|
|
515
515
|
|
|
516
516
|
# Main functions #
|
|
517
|
-
|
|
517
|
+
#----------------#
|
|
518
518
|
|
|
519
519
|
# All except 'float' #
|
|
520
|
-
|
|
520
|
+
#~~~~~~~~~~~~~~~~~~~~#
|
|
521
521
|
|
|
522
522
|
def dt_obj_converter(datetime_obj,
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
523
|
+
convert_to,
|
|
524
|
+
unit="s",
|
|
525
|
+
float_class="d",
|
|
526
|
+
int_class="int",
|
|
527
|
+
dt_fmt_str=None,
|
|
528
|
+
dayfirst=False,
|
|
529
|
+
yearfirst=False):
|
|
530
530
|
|
|
531
531
|
"""
|
|
532
532
|
Convert a date/time object to another, including float and string representation.
|
|
@@ -604,16 +604,24 @@ def dt_obj_converter(datetime_obj,
|
|
|
604
604
|
"""
|
|
605
605
|
|
|
606
606
|
# Input validation #
|
|
607
|
-
|
|
607
|
+
#-#-#-#-#-#-#-#-#-#-
|
|
608
608
|
|
|
609
609
|
# Object type to convert to #
|
|
610
610
|
if not convert_to:
|
|
611
611
|
raise ValueError("Argument 'convert_to' not provided.")
|
|
612
612
|
|
|
613
613
|
# Helper function to perform conversion and handle exceptions
|
|
614
|
-
def perform_conversion(conversion_dict, obj,
|
|
614
|
+
def perform_conversion(conversion_dict, obj, **kwargs):
|
|
615
615
|
try:
|
|
616
|
-
return conversion_dict.get(convert_to)(
|
|
616
|
+
return conversion_dict.get(convert_to)(
|
|
617
|
+
obj,
|
|
618
|
+
kwargs.get("unit"),
|
|
619
|
+
kwargs.get("float_class"),
|
|
620
|
+
kwargs.get("int_class"),
|
|
621
|
+
kwargs.get("dt_fmt_str"),
|
|
622
|
+
kwargs.get("dayfirst"),
|
|
623
|
+
kwargs.get("yearfirst"),
|
|
624
|
+
)
|
|
617
625
|
except Exception as err:
|
|
618
626
|
raise RuntimeError(f"Error during conversion to '{convert_to}': {err}")
|
|
619
627
|
|
|
@@ -625,8 +633,8 @@ def dt_obj_converter(datetime_obj,
|
|
|
625
633
|
_validate_option("Numpy float precision class", float_class, _FLOAT_CLASS_LIST)
|
|
626
634
|
_validate_option("Numpy integer precision class", int_class, _INT_CLASS_LIST)
|
|
627
635
|
|
|
628
|
-
#
|
|
629
|
-
|
|
636
|
+
# Program progression #
|
|
637
|
+
#-#-#-#-#-#-#-#-#-#-#-#
|
|
630
638
|
|
|
631
639
|
# Get the object type's name #
|
|
632
640
|
obj_type = get_type_str(datetime_obj, lowercase=True)
|
|
@@ -647,9 +655,11 @@ def dt_obj_converter(datetime_obj,
|
|
|
647
655
|
#---------------------#
|
|
648
656
|
|
|
649
657
|
# Exclusively to 'float' #
|
|
650
|
-
|
|
658
|
+
#~~~~~~~~~~~~~~~~~~~~~~~~#
|
|
651
659
|
|
|
652
660
|
# Scalar complex data #
|
|
661
|
+
#-#-#-#-#-#-#-#-#-#-#-#
|
|
662
|
+
|
|
653
663
|
def _total_dt_unit(datetime_obj, unit, float_class=None, int_class=None):
|
|
654
664
|
"""
|
|
655
665
|
Convert a datetime object into total time based on the specified unit
|
|
@@ -680,13 +690,13 @@ def _total_dt_unit(datetime_obj, unit, float_class=None, int_class=None):
|
|
|
680
690
|
If an error occurs during the conversion process.
|
|
681
691
|
"""
|
|
682
692
|
# Input validation #
|
|
683
|
-
|
|
693
|
+
####################
|
|
684
694
|
|
|
685
695
|
# Current function name #
|
|
686
696
|
current_function = get_func_name()
|
|
687
697
|
|
|
688
|
-
#
|
|
689
|
-
|
|
698
|
+
# Program progression #
|
|
699
|
+
#######################
|
|
690
700
|
|
|
691
701
|
unit_factor = UNIT_FACTOR_DICT.get(unit)
|
|
692
702
|
obj_type = get_type_str(datetime_obj, lowercase=True)
|
|
@@ -809,7 +819,7 @@ def _to_string(dt_obj, unit, dt_fmt_str):
|
|
|
809
819
|
return dt_obj.strftime(dt_fmt_str)
|
|
810
820
|
|
|
811
821
|
# Handle np.ndarray with datetime-like objects
|
|
812
|
-
if isinstance(dt_obj, np.ndarray
|
|
822
|
+
if isinstance(dt_obj, np.ndarray):
|
|
813
823
|
try:
|
|
814
824
|
dt_obj = np.vectorize(lambda x: _to_datetime_aux(x, unit).strftime(dt_fmt_str))(dt_obj)
|
|
815
825
|
except Exception as e:
|
|
@@ -819,7 +829,7 @@ def _to_string(dt_obj, unit, dt_fmt_str):
|
|
|
819
829
|
# Handle pd.Series
|
|
820
830
|
if isinstance(dt_obj, pd.Series):
|
|
821
831
|
try:
|
|
822
|
-
return dt_obj.apply(lambda dfs_col: dfs_col.
|
|
832
|
+
return dt_obj.apply(lambda dfs_col: dfs_col.strftime(dt_fmt_str)
|
|
823
833
|
if hasattr(dfs_col, 'strftime') else str(dfs_col))
|
|
824
834
|
except Exception as e:
|
|
825
835
|
raise ValueError(f"Error in converting pd.Series to string: {e}")
|
|
@@ -879,11 +889,11 @@ def __time_component_to_float(t):
|
|
|
879
889
|
time_component_float : int
|
|
880
890
|
Seconds relative to the Unix epoch.
|
|
881
891
|
"""
|
|
882
|
-
time_component_float =
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
return time_component_float
|
|
892
|
+
time_component_float = timedelta(hours=t.hour,
|
|
893
|
+
minutes=t.minute,
|
|
894
|
+
seconds=t.second,
|
|
895
|
+
microseconds=t.microsecond)
|
|
896
|
+
return time_component_float.total_seconds()
|
|
887
897
|
|
|
888
898
|
|
|
889
899
|
def _to_datetime(dt_obj, unit=None):
|
|
@@ -1052,14 +1062,14 @@ _INT_CLASS_LIST = [np.int8, np.int16, "i", np.float32, "int", np.int64]
|
|
|
1052
1062
|
#--------------------------#
|
|
1053
1063
|
|
|
1054
1064
|
# Time parsing #
|
|
1055
|
-
|
|
1065
|
+
#~~~~~~~~~~~~~~#
|
|
1056
1066
|
|
|
1057
1067
|
# String #
|
|
1058
1068
|
#-#-#-#-#-
|
|
1059
1069
|
|
|
1060
1070
|
TIME_STR_PARSING_DICT = {
|
|
1061
1071
|
"datetime" : lambda datetime_str, dt_fmt_str: datetime.strptime(datetime_str, dt_fmt_str),
|
|
1062
|
-
"dateutil" : lambda datetime_str, dt_fmt_str:
|
|
1072
|
+
"dateutil" : lambda datetime_str, dt_fmt_str: parse(datetime_str),
|
|
1063
1073
|
"pandas" : lambda datetime_str, dt_fmt_str, unit, dayfirst=False, yearfirst=False : pd.to_datetime(datetime_str, format=dt_fmt_str, dayfirst=dayfirst, yearfirst=yearfirst),
|
|
1064
1074
|
"numpy" : lambda datetime_str, _, unit : np.datetime64(datetime_str, unit),
|
|
1065
1075
|
"arrow" : lambda datetime_str, dt_fmt_str: _arrow_get_with_import(datetime_str, dt_fmt_str)
|
|
@@ -1081,63 +1091,63 @@ FLOATED_TIME_PARSING_DICT = {
|
|
|
1081
1091
|
|
|
1082
1092
|
# To other objects #
|
|
1083
1093
|
DT_OBJ_CONVERSION_DICT = {
|
|
1084
|
-
"float" : lambda dt_obj,
|
|
1085
|
-
"time" : lambda dt_obj,
|
|
1086
|
-
"pandas" : lambda dt_obj, unit
|
|
1087
|
-
"numpy" : lambda dt_obj, unit
|
|
1088
|
-
"arrow" : lambda dt_obj,
|
|
1089
|
-
"str" : lambda dt_obj, unit
|
|
1094
|
+
"float" : lambda dt_obj, _, __, ___, ____, _____, ______ : dt_obj.timestamp(),
|
|
1095
|
+
"time" : lambda dt_obj, _, __, ___, ____, _____, ______ : dt_obj.timetuple(),
|
|
1096
|
+
"pandas" : lambda dt_obj, unit, __, ___, ____, dayfirst, yearfirst : _to_pandas(_tzinfo_remover(dt_obj), unit, dayfirst, yearfirst),
|
|
1097
|
+
"numpy" : lambda dt_obj, unit, __, ___, ____, _____, ______ : _to_numpy(_tzinfo_remover(dt_obj), unit),
|
|
1098
|
+
"arrow" : lambda dt_obj, _, __, ___, ____, _____, ______ : _to_arrow(dt_obj),
|
|
1099
|
+
"str" : lambda dt_obj, unit, __, ___, dt_fmt_str, _____, ______ : _to_string(dt_obj, unit, dt_fmt_str)
|
|
1090
1100
|
}
|
|
1091
1101
|
|
|
1092
1102
|
DT64_OBJ_CONVERSION_DICT = {
|
|
1093
|
-
"float" : lambda dt_obj, unit
|
|
1094
|
-
"datetime" : lambda dt_obj, unit
|
|
1095
|
-
"time" : lambda dt_obj, unit
|
|
1096
|
-
"pandas" : lambda dt_obj, unit
|
|
1097
|
-
"arrow" : lambda dt_obj,
|
|
1098
|
-
"str" : lambda dt_obj, unit
|
|
1103
|
+
"float" : lambda dt_obj, unit, float_class, __, ___, _____, ______ : _to_float(dt_obj, unit, float_class),
|
|
1104
|
+
"datetime" : lambda dt_obj, unit, __, ___, ____, _____, ______ : _to_datetime(dt_obj, unit),
|
|
1105
|
+
"time" : lambda dt_obj, unit, __, ___, ____, _____, ______ : _to_time_struct(dt_obj, unit),
|
|
1106
|
+
"pandas" : lambda dt_obj, unit, __, ___, ____, dayfirst, yearfirst : _to_pandas(dt_obj, unit, dayfirst, yearfirst),
|
|
1107
|
+
"arrow" : lambda dt_obj, _, __, ___, ____, _____, ______ : _to_arrow(dt_obj),
|
|
1108
|
+
"str" : lambda dt_obj, unit, __, ___, dt_fmt_str, _____, ______ : _to_string(_to_datetime(dt_obj), unit, dt_fmt_str)
|
|
1099
1109
|
}
|
|
1100
1110
|
|
|
1101
1111
|
DT_TIME_OBJ_CONVERSION_DICT = {
|
|
1102
|
-
"float" : lambda dt_obj, unit
|
|
1103
|
-
"datetime" : lambda dt_obj, unit
|
|
1104
|
-
"time" : lambda dt_obj,
|
|
1105
|
-
"pandas" : lambda dt_obj, unit
|
|
1106
|
-
"numpy" : lambda dt_obj, unit
|
|
1107
|
-
"arrow" : lambda dt_obj,
|
|
1108
|
-
"str" : lambda dt_obj, unit
|
|
1112
|
+
"float" : lambda dt_obj, unit, float_class, __, ___, _____, ______ : _to_float(dt_obj, unit, float_class),
|
|
1113
|
+
"datetime" : lambda dt_obj, unit, __, ___, ____, _____, ______ : _to_datetime(dt_obj, unit),
|
|
1114
|
+
"time" : lambda dt_obj, _, __, ___, ____, _____, ______ : _to_time_struct(dt_obj),
|
|
1115
|
+
"pandas" : lambda dt_obj, unit, __, ___, ____, dayfirst, yearfirst : _to_pandas(_to_datetime(dt_obj), unit, dayfirst, yearfirst),
|
|
1116
|
+
"numpy" : lambda dt_obj, unit, __, ___, ____, _____, ______ : _to_numpy(_to_datetime(dt_obj), unit),
|
|
1117
|
+
"arrow" : lambda dt_obj, _, __, ___, ____, _____, ______ : _to_arrow(dt_obj),
|
|
1118
|
+
"str" : lambda dt_obj, unit, __, ___, dt_fmt_str, _____, ______ : _to_string(dt_obj, unit, dt_fmt_str)
|
|
1109
1119
|
}
|
|
1110
1120
|
|
|
1111
1121
|
TIMESTAMP_OBJ_CONVERSION_DICT = {
|
|
1112
|
-
"float" : lambda dt_obj, unit
|
|
1113
|
-
"datetime" : lambda dt_obj, unit
|
|
1114
|
-
"time" : lambda dt_obj,
|
|
1115
|
-
"numpy" : lambda dt_obj,
|
|
1116
|
-
"arrow" : lambda dt_obj,
|
|
1117
|
-
"str" : lambda dt_obj, unit
|
|
1122
|
+
"float" : lambda dt_obj, unit, float_class, __, ___, _____, ______ : _to_float(dt_obj, unit, float_class),
|
|
1123
|
+
"datetime" : lambda dt_obj, unit, __, ___, ____, _____, ______ : _to_datetime(dt_obj, unit),
|
|
1124
|
+
"time" : lambda dt_obj, _, __, ___, ____, _____, ______ : _to_time_struct(dt_obj),
|
|
1125
|
+
"numpy" : lambda dt_obj, _, __, ___, ____, _____, ______ : dt_obj.to_numpy(),
|
|
1126
|
+
"arrow" : lambda dt_obj, _, __, ___, ____, _____, ______ : _to_arrow(dt_obj),
|
|
1127
|
+
"str" : lambda dt_obj, unit, __, ___, dt_fmt_str, _____, ______ : _to_string(dt_obj, unit, dt_fmt_str)
|
|
1118
1128
|
}
|
|
1119
1129
|
|
|
1120
1130
|
ARROW_OBJ_CONVERSION_DICT = {
|
|
1121
|
-
"float" : lambda dt_obj, unit
|
|
1122
|
-
"datetime" : lambda dt_obj, unit
|
|
1123
|
-
"time" : lambda dt_obj,
|
|
1124
|
-
"pandas" : lambda dt_obj, unit
|
|
1125
|
-
"numpy" : lambda dt_obj, unit
|
|
1126
|
-
"str" : lambda dt_obj, unit
|
|
1131
|
+
"float" : lambda dt_obj, unit, float_class, __, ___, _____, ______ : _to_float(dt_obj, unit, float_class),
|
|
1132
|
+
"datetime" : lambda dt_obj, unit, __, ___, ____, _____, ______ : _to_datetime(dt_obj, unit),
|
|
1133
|
+
"time" : lambda dt_obj, _, __, ___, ____, _____, ______ : _to_time_struct(dt_obj),
|
|
1134
|
+
"pandas" : lambda dt_obj, unit, __, ___, ____, dayfirst, yearfirst : _to_pandas(dt_obj, unit, dayfirst, yearfirst),
|
|
1135
|
+
"numpy" : lambda dt_obj, unit, __, ___, ____, _____, ______ : _to_numpy(dt_obj, unit),
|
|
1136
|
+
"str" : lambda dt_obj, unit, __, ___, dt_fmt_str, _____, ______ : _to_string(dt_obj, unit, dt_fmt_str)
|
|
1127
1137
|
}
|
|
1128
1138
|
|
|
1129
1139
|
TIME_STT_OBJ_CONVERSION_DICT = {
|
|
1130
|
-
"float" : lambda dt_obj, unit
|
|
1131
|
-
"datetime" : lambda dt_obj, unit
|
|
1132
|
-
"pandas" : lambda dt_obj, unit
|
|
1133
|
-
"numpy" : lambda dt_obj, unit
|
|
1134
|
-
"arrow" : lambda dt_obj,
|
|
1140
|
+
"float" : lambda dt_obj, unit, float_class, __, ___, _____, ______ : _to_float(dt_obj, unit, float_class),
|
|
1141
|
+
"datetime" : lambda dt_obj, unit, __, ___, ____, _____, ______ : _to_datetime(dt_obj, unit),
|
|
1142
|
+
"pandas" : lambda dt_obj, unit, __, ___, ____, _____, ______ : pd.Timestamp(*dt_obj[:6], unit=unit),
|
|
1143
|
+
"numpy" : lambda dt_obj, unit, __, ___, ____, _____, ______ : np.datetime64(datetime(*dt_obj[:6]), unit),
|
|
1144
|
+
"arrow" : lambda dt_obj, _, __, ___, ____, _____, ______ : _to_arrow(dt_obj),
|
|
1135
1145
|
}
|
|
1136
1146
|
|
|
1137
1147
|
_DT_LIKE_OBJ_CONVERSION_DICT = {
|
|
1138
|
-
"float" : lambda dt_obj, unit
|
|
1139
|
-
"pandas" : lambda dt_obj, unit
|
|
1140
|
-
"str" : lambda dt_obj, unit
|
|
1148
|
+
"float" : lambda dt_obj, unit, float_class, int_class, ___, _____, ______ : _total_dt_unit(dt_obj, unit, float_class, int_class),
|
|
1149
|
+
"pandas" : lambda dt_obj, unit, __, ___, ____, _____, ______ : _to_datetime(dt_obj, unit),
|
|
1150
|
+
"str" : lambda dt_obj, unit, __, ___, dt_fmt_str, _____, ______ : _to_string(dt_obj, unit, dt_fmt_str)
|
|
1141
1151
|
}
|
|
1142
1152
|
|
|
1143
1153
|
# Enumerate all possibilities #
|
|
@@ -1155,13 +1165,13 @@ CONVERSION_OPT_DICT = {
|
|
|
1155
1165
|
|
|
1156
1166
|
# Exclusively to floated time #
|
|
1157
1167
|
_TOTAL_TIME_UNIT_DICT = {
|
|
1158
|
-
"datetime" : lambda dt_obj, _ : dt_obj.timestamp(),
|
|
1159
|
-
"datetime64" : lambda dt_obj, unit, float_class : dt_obj.astype(f"timedelta64[{unit}]").astype(float_class),
|
|
1160
|
-
"struct_time" : lambda dt_obj, _ : datetime(*dt_obj[:6]),
|
|
1161
|
-
"arrow" : lambda dt_obj, _ : dt_obj.float_timestamp,
|
|
1162
|
-
"dataframe" : lambda dt_obj, _, int_class, unit_factor : _total_dt_complex_data(dt_obj, int_class, unit_factor),
|
|
1163
|
-
"series" : lambda dt_obj, _, int_class, unit_factor : _total_dt_complex_data(dt_obj, int_class, unit_factor),
|
|
1164
|
-
"ndarray" : lambda dt_obj, unit, float_class, _ : dt_obj.astype(f"datetime64[{unit}]").astype(float_class)
|
|
1168
|
+
"datetime" : lambda dt_obj, _, __, ___, ____ : dt_obj.timestamp(),
|
|
1169
|
+
"datetime64" : lambda dt_obj, unit, float_class, _, __ : dt_obj.astype(f"timedelta64[{unit}]").astype(float_class),
|
|
1170
|
+
"struct_time" : lambda dt_obj, _, __, ___, ____ : datetime(*dt_obj[:6]),
|
|
1171
|
+
"arrow" : lambda dt_obj, _, __, ___, ____ : dt_obj.float_timestamp,
|
|
1172
|
+
"dataframe" : lambda dt_obj, _, __, int_class, unit_factor : _total_dt_complex_data(dt_obj, int_class, unit_factor),
|
|
1173
|
+
"series" : lambda dt_obj, _, __, int_class, unit_factor : _total_dt_complex_data(dt_obj, int_class, unit_factor),
|
|
1174
|
+
"ndarray" : lambda dt_obj, unit, float_class, _, __ : dt_obj.astype(f"datetime64[{unit}]").astype(float_class)
|
|
1165
1175
|
}
|
|
1166
1176
|
|
|
1167
1177
|
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "pygenutils"
|
|
7
|
-
version = "16.
|
|
7
|
+
version = "16.3.1"
|
|
8
8
|
license = {file = "LICENSE"}
|
|
9
9
|
description = "A comprehensive Python utility library for general-purpose and specialised tasks"
|
|
10
10
|
keywords = ["utilities", "python", "general-purpose", "file handling", "string processing"]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|