pygenutils 16.1.3__tar.gz → 16.2.0__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.1.3/pygenutils.egg-info → pygenutils-16.2.0}/PKG-INFO +10 -3
- {pygenutils-16.1.3 → pygenutils-16.2.0}/README.md +7 -1
- {pygenutils-16.1.3 → pygenutils-16.2.0}/pygenutils/__init__.py +1 -1
- {pygenutils-16.1.3 → pygenutils-16.2.0}/pygenutils/strings/string_handler.py +30 -6
- {pygenutils-16.1.3 → pygenutils-16.2.0}/pygenutils/strings/text_formatters.py +56 -35
- {pygenutils-16.1.3 → pygenutils-16.2.0}/pygenutils/time_handling/time_formatters.py +37 -4
- {pygenutils-16.1.3 → pygenutils-16.2.0}/pygenutils/time_handling/time_utils.py +16 -7
- {pygenutils-16.1.3 → pygenutils-16.2.0/pygenutils.egg-info}/PKG-INFO +10 -3
- {pygenutils-16.1.3 → pygenutils-16.2.0}/pygenutils.egg-info/requires.txt +2 -0
- {pygenutils-16.1.3 → pygenutils-16.2.0}/pyproject.toml +2 -2
- {pygenutils-16.1.3 → pygenutils-16.2.0}/LICENSE +0 -0
- {pygenutils-16.1.3 → pygenutils-16.2.0}/MANIFEST.in +0 -0
- {pygenutils-16.1.3 → pygenutils-16.2.0}/pygenutils/arrays_and_lists/__init__.py +0 -0
- {pygenutils-16.1.3 → pygenutils-16.2.0}/pygenutils/arrays_and_lists/conversions.py +0 -0
- {pygenutils-16.1.3 → pygenutils-16.2.0}/pygenutils/arrays_and_lists/data_manipulation.py +0 -0
- {pygenutils-16.1.3 → pygenutils-16.2.0}/pygenutils/arrays_and_lists/maths.py +0 -0
- {pygenutils-16.1.3 → pygenutils-16.2.0}/pygenutils/arrays_and_lists/patterns.py +0 -0
- {pygenutils-16.1.3 → pygenutils-16.2.0}/pygenutils/audio_and_video/__init__.py +0 -0
- {pygenutils-16.1.3 → pygenutils-16.2.0}/pygenutils/audio_and_video/audio_and_video_manipulation.py +0 -0
- {pygenutils-16.1.3 → pygenutils-16.2.0}/pygenutils/audio_and_video/merge_audio_and_video.py +0 -0
- {pygenutils-16.1.3 → pygenutils-16.2.0}/pygenutils/audio_and_video/merge_audio_or_video.py +0 -0
- {pygenutils-16.1.3 → pygenutils-16.2.0}/pygenutils/audio_and_video/trim_media.py +0 -0
- {pygenutils-16.1.3 → pygenutils-16.2.0}/pygenutils/dictionaries/__init__.py +0 -0
- {pygenutils-16.1.3 → pygenutils-16.2.0}/pygenutils/dictionaries/dict_handler.py +0 -0
- {pygenutils-16.1.3 → pygenutils-16.2.0}/pygenutils/dictionaries/dict_operators.py +0 -0
- {pygenutils-16.1.3 → pygenutils-16.2.0}/pygenutils/number_bases/__init__.py +0 -0
- {pygenutils-16.1.3 → pygenutils-16.2.0}/pygenutils/number_bases/base_converters.py +0 -0
- {pygenutils-16.1.3 → pygenutils-16.2.0}/pygenutils/number_bases/binary_operations.py +0 -0
- {pygenutils-16.1.3 → pygenutils-16.2.0}/pygenutils/number_bases/bitwise_operators.py +0 -0
- {pygenutils-16.1.3 → pygenutils-16.2.0}/pygenutils/number_bases/mathematical_utils.py +0 -0
- {pygenutils-16.1.3 → pygenutils-16.2.0}/pygenutils/operative_systems/__init__.py +0 -0
- {pygenutils-16.1.3 → pygenutils-16.2.0}/pygenutils/operative_systems/os_operations.py +0 -0
- {pygenutils-16.1.3 → pygenutils-16.2.0}/pygenutils/sets_and_intervals/__init__.py +0 -0
- {pygenutils-16.1.3 → pygenutils-16.2.0}/pygenutils/sets_and_intervals/interval_handler.py +0 -0
- {pygenutils-16.1.3 → pygenutils-16.2.0}/pygenutils/sets_and_intervals/sets_handler.py +0 -0
- {pygenutils-16.1.3 → pygenutils-16.2.0}/pygenutils/strings/__init__.py +0 -0
- {pygenutils-16.1.3 → pygenutils-16.2.0}/pygenutils/time_handling/__init__.py +0 -0
- {pygenutils-16.1.3 → pygenutils-16.2.0}/pygenutils/time_handling/calendar_utils.py +0 -0
- {pygenutils-16.1.3 → pygenutils-16.2.0}/pygenutils/time_handling/countdown.py +0 -0
- {pygenutils-16.1.3 → pygenutils-16.2.0}/pygenutils/time_handling/date_and_time_maths.py +0 -0
- {pygenutils-16.1.3 → pygenutils-16.2.0}/pygenutils/time_handling/date_and_time_utils.py +0 -0
- {pygenutils-16.1.3 → pygenutils-16.2.0}/pygenutils/time_handling/program_snippet_exec_timers.py +0 -0
- {pygenutils-16.1.3 → pygenutils-16.2.0}/pygenutils.egg-info/SOURCES.txt +0 -0
- {pygenutils-16.1.3 → pygenutils-16.2.0}/pygenutils.egg-info/dependency_links.txt +0 -0
- {pygenutils-16.1.3 → pygenutils-16.2.0}/pygenutils.egg-info/top_level.txt +0 -0
- {pygenutils-16.1.3 → pygenutils-16.2.0}/setup.cfg +0 -0
- {pygenutils-16.1.3 → pygenutils-16.2.0}/setup.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pygenutils
|
|
3
|
-
Version: 16.
|
|
3
|
+
Version: 16.2.0
|
|
4
4
|
Summary: A comprehensive Python utility library for general-purpose and specialised tasks
|
|
5
5
|
Author-email: Jon Ander Gabantxo <jagabantxo@gmail.com>
|
|
6
6
|
License: MIT License
|
|
@@ -47,9 +47,10 @@ Requires-Dist: numpy<2.0.0,>=1.21.0
|
|
|
47
47
|
Requires-Dist: pandas<2.0.0,>=1.3.0
|
|
48
48
|
Requires-Dist: filewise>=3.11.0
|
|
49
49
|
Requires-Dist: paramlib>=3.4.3
|
|
50
|
-
Requires-Dist: arrow>=1.2.0
|
|
51
50
|
Provides-Extra: xarray
|
|
52
51
|
Requires-Dist: xarray>=2024.2.0; extra == "xarray"
|
|
52
|
+
Provides-Extra: arrow
|
|
53
|
+
Requires-Dist: arrow>=1.2.0; extra == "arrow"
|
|
53
54
|
Provides-Extra: dev
|
|
54
55
|
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
55
56
|
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
@@ -117,11 +118,17 @@ This package has minimal external dependencies and is designed to be lightweight
|
|
|
117
118
|
**For regular users** who want to use the package in their projects:
|
|
118
119
|
|
|
119
120
|
```bash
|
|
120
|
-
pip install pygenutils
|
|
121
|
+
pip install pygenutils # Core functionality
|
|
122
|
+
pip install pygenutils[arrow] # With arrow support (optional)
|
|
121
123
|
```
|
|
122
124
|
|
|
123
125
|
This automatically installs `pygenutils` and all its dependencies with version constraints.
|
|
124
126
|
|
|
127
|
+
**How It Works Now**:
|
|
128
|
+
|
|
129
|
+
- `pip install pygenutils` - Core functionality without arrow dependency
|
|
130
|
+
- `pip install pygenutils[arrow]` - With arrow support for enhanced time handling features
|
|
131
|
+
|
|
125
132
|
### Package Updates
|
|
126
133
|
|
|
127
134
|
To stay up-to-date with the latest version of this package, simply run:
|
|
@@ -56,11 +56,17 @@ This package has minimal external dependencies and is designed to be lightweight
|
|
|
56
56
|
**For regular users** who want to use the package in their projects:
|
|
57
57
|
|
|
58
58
|
```bash
|
|
59
|
-
pip install pygenutils
|
|
59
|
+
pip install pygenutils # Core functionality
|
|
60
|
+
pip install pygenutils[arrow] # With arrow support (optional)
|
|
60
61
|
```
|
|
61
62
|
|
|
62
63
|
This automatically installs `pygenutils` and all its dependencies with version constraints.
|
|
63
64
|
|
|
65
|
+
**How It Works Now**:
|
|
66
|
+
|
|
67
|
+
- `pip install pygenutils` - Core functionality without arrow dependency
|
|
68
|
+
- `pip install pygenutils[arrow]` - With arrow support for enhanced time handling features
|
|
69
|
+
|
|
64
70
|
### Package Updates
|
|
65
71
|
|
|
66
72
|
To stay up-to-date with the latest version of this package, simply run:
|
|
@@ -109,7 +109,14 @@ def find_substring_index(string,
|
|
|
109
109
|
find_whole_words,
|
|
110
110
|
all_matches)
|
|
111
111
|
else:
|
|
112
|
-
|
|
112
|
+
if return_match_index == "lo":
|
|
113
|
+
return string.find(substring)
|
|
114
|
+
elif return_match_index == "hi":
|
|
115
|
+
return string.rfind(substring)
|
|
116
|
+
else: # return_match_index == "both"
|
|
117
|
+
first_index = string.find(substring)
|
|
118
|
+
last_index = string.rfind(substring)
|
|
119
|
+
return [first_index, last_index]
|
|
113
120
|
|
|
114
121
|
|
|
115
122
|
elif get_type_str(string) in ["list", "ndarray", "tuple"]:
|
|
@@ -118,8 +125,18 @@ def find_substring_index(string,
|
|
|
118
125
|
# Simple search without advanced features
|
|
119
126
|
if not advanced_search:
|
|
120
127
|
if get_type_str(string) == "ndarray":
|
|
121
|
-
|
|
122
|
-
|
|
128
|
+
if return_match_index == "lo":
|
|
129
|
+
match_indices = char.find(string, substring, start=start, end=end)
|
|
130
|
+
return [idx for idx in match_indices if idx != -1]
|
|
131
|
+
elif return_match_index == "hi":
|
|
132
|
+
match_indices = char.rfind(string, substring, start=start, end=end)
|
|
133
|
+
return [idx for idx in match_indices if idx != -1]
|
|
134
|
+
else: # return_match_index == "both"
|
|
135
|
+
first_indices = char.find(string, substring, start=start, end=end)
|
|
136
|
+
last_indices = char.rfind(string, substring, start=start, end=end)
|
|
137
|
+
first_filtered = [idx for idx in first_indices if idx != -1]
|
|
138
|
+
last_filtered = [idx for idx in last_indices if idx != -1]
|
|
139
|
+
return [first_filtered, last_filtered]
|
|
123
140
|
|
|
124
141
|
else:
|
|
125
142
|
if end is None:
|
|
@@ -144,7 +161,14 @@ def find_substring_index(string,
|
|
|
144
161
|
substring = flatten_list(substring)
|
|
145
162
|
|
|
146
163
|
if not advanced_search:
|
|
147
|
-
|
|
164
|
+
if return_match_index == "lo":
|
|
165
|
+
return char.find(string, substring, start=start, end=end)
|
|
166
|
+
elif return_match_index == "hi":
|
|
167
|
+
return char.rfind(string, substring, start=start, end=end)
|
|
168
|
+
else: # return_match_index == "both"
|
|
169
|
+
first_indices = char.find(string, substring, start=start, end=end)
|
|
170
|
+
last_indices = char.rfind(string, substring, start=start, end=end)
|
|
171
|
+
return [first_indices, last_indices]
|
|
148
172
|
else:
|
|
149
173
|
match_indices = _advanced_pattern_searcher(string, substring,
|
|
150
174
|
return_match_index,
|
|
@@ -739,7 +763,7 @@ def strip(string, strip_option='strip', chars=None):
|
|
|
739
763
|
|
|
740
764
|
Parameters
|
|
741
765
|
----------
|
|
742
|
-
strip_option: {'strip', 'lstrip', '
|
|
766
|
+
strip_option: {'strip', 'lstrip', 'rstrip'} or None
|
|
743
767
|
Location of the white spaces or substring to strip.
|
|
744
768
|
Default option is the widely used 'strip'.
|
|
745
769
|
|
|
@@ -833,4 +857,4 @@ REPLACE_ACTIONS = {
|
|
|
833
857
|
"ndarray": lambda s, sb2find, sb2replace, _ : char.replace(s, sb2find, sb2replace),
|
|
834
858
|
"dataframe": lambda s, sb2find, sb2replace, _ : DataFrame.replace(s, sb2find, sb2replace),
|
|
835
859
|
"series": lambda s, sb2find, sb2replace, _ : Series.replace(s, sb2find, sb2replace),
|
|
836
|
-
}
|
|
860
|
+
}
|
|
@@ -163,13 +163,13 @@ def print_percent_string(string2format, arg_obj):
|
|
|
163
163
|
# String font effects #
|
|
164
164
|
#---------------------#
|
|
165
165
|
|
|
166
|
-
def string_underliner(string, underline_char="-"):
|
|
166
|
+
def string_underliner(string, underline_char="-", width=None):
|
|
167
167
|
"""
|
|
168
168
|
Underlines a given string with the specified character.
|
|
169
169
|
|
|
170
170
|
If the string contains multiple lines, each line will be underlined
|
|
171
171
|
individually with the same character, keeping the length of the underline
|
|
172
|
-
consistent with each line's length.
|
|
172
|
+
consistent with each line's length (or the specified width).
|
|
173
173
|
|
|
174
174
|
Parameters
|
|
175
175
|
----------
|
|
@@ -179,24 +179,40 @@ def string_underliner(string, underline_char="-"):
|
|
|
179
179
|
underline_char : str, optional
|
|
180
180
|
The character used to underline the string.
|
|
181
181
|
Defaults to a dash ("-").
|
|
182
|
+
|
|
183
|
+
width : int, optional
|
|
184
|
+
The total width for centering the string. If None, uses the natural
|
|
185
|
+
length of each line. If specified, the string will be centered within
|
|
186
|
+
this width using the underline character as padding.
|
|
182
187
|
|
|
183
188
|
Returns
|
|
184
189
|
-------
|
|
185
190
|
str_underlined : str
|
|
186
191
|
The original string with an underline applied to each line.
|
|
187
192
|
For multiline strings, each line is individually underlined.
|
|
193
|
+
If width is specified, each line is centered within that width.
|
|
188
194
|
|
|
189
|
-
|
|
190
|
-
|
|
195
|
+
Examples
|
|
196
|
+
--------
|
|
191
197
|
For a single-line string:
|
|
192
198
|
|
|
193
199
|
>>> string_underliner("Hello", "*")
|
|
194
200
|
'Hello\n*****'
|
|
195
201
|
|
|
202
|
+
For a single-line string with width:
|
|
203
|
+
|
|
204
|
+
>>> string_underliner("Hello", "*", width=15)
|
|
205
|
+
'*****Hello*****\n***************'
|
|
206
|
+
|
|
196
207
|
For a multiline string:
|
|
197
208
|
|
|
198
209
|
>>> string_underliner("Hello\nWorld", "*")
|
|
199
210
|
'Hello\n*****\nWorld\n*****'
|
|
211
|
+
|
|
212
|
+
For a multiline string with width:
|
|
213
|
+
|
|
214
|
+
>>> string_underliner("Hello\nWorld", "*", width=15)
|
|
215
|
+
'*****Hello*****\n***************\n*****World*****\n***************'
|
|
200
216
|
"""
|
|
201
217
|
|
|
202
218
|
# Check if the string contains newlines, indicating a multiline string
|
|
@@ -210,17 +226,32 @@ def string_underliner(string, underline_char="-"):
|
|
|
210
226
|
# Build the underlined string by iterating over each line
|
|
211
227
|
str_underlined = ""
|
|
212
228
|
for word in word_list:
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
229
|
+
if width is not None:
|
|
230
|
+
# Center the word within the specified width
|
|
231
|
+
centered_word = word.center(width, underline_char)
|
|
232
|
+
underline = underline_char * width
|
|
233
|
+
else:
|
|
234
|
+
# Use natural length
|
|
235
|
+
centered_word = word
|
|
236
|
+
underline = underline_char * len(word)
|
|
237
|
+
|
|
238
|
+
str_underlined += f"{centered_word}\n{underline}\n"
|
|
216
239
|
|
|
217
240
|
# Remove the last newline character to avoid an extra empty line
|
|
218
241
|
str_underlined = str_underlined.rstrip(newline_char)
|
|
219
242
|
|
|
220
243
|
else:
|
|
221
|
-
# For a single-line string
|
|
222
|
-
|
|
223
|
-
|
|
244
|
+
# For a single-line string
|
|
245
|
+
if width is not None:
|
|
246
|
+
# Center the string within the specified width
|
|
247
|
+
centered_string = string.center(width, underline_char)
|
|
248
|
+
underline = underline_char * width
|
|
249
|
+
else:
|
|
250
|
+
# Use natural length
|
|
251
|
+
centered_string = string
|
|
252
|
+
underline = underline_char * len(string)
|
|
253
|
+
|
|
254
|
+
str_underlined = f"{centered_string}\n{underline}"
|
|
224
255
|
|
|
225
256
|
return str_underlined
|
|
226
257
|
|
|
@@ -316,7 +347,7 @@ def format_table(nested_dict,
|
|
|
316
347
|
|
|
317
348
|
# Build the header string
|
|
318
349
|
header_row = column_delimiter + \
|
|
319
|
-
column_delimiter.join(
|
|
350
|
+
column_delimiter.join(header.center(column_widths[header])
|
|
320
351
|
for header in headers) + \
|
|
321
352
|
column_delimiter
|
|
322
353
|
|
|
@@ -330,13 +361,13 @@ def format_table(nested_dict,
|
|
|
330
361
|
content_rows = []
|
|
331
362
|
for idx, subdict in nested_dict.items():
|
|
332
363
|
if display_index:
|
|
333
|
-
row = [
|
|
364
|
+
row = [str(idx).center(column_widths[index_header])]
|
|
334
365
|
else:
|
|
335
366
|
row = []
|
|
336
367
|
for key in keys:
|
|
337
368
|
original_key = list(subdict.keys())[keys.index(key)]
|
|
338
369
|
value = subdict.get(original_key, "")
|
|
339
|
-
row.append(
|
|
370
|
+
row.append(str(value).center(column_widths[key]))
|
|
340
371
|
content_rows.append(column_delimiter + column_delimiter.join(row) + column_delimiter)
|
|
341
372
|
|
|
342
373
|
# Combine all parts
|
|
@@ -404,8 +435,7 @@ def format_table_from_list(dict_list,
|
|
|
404
435
|
If display_index = True, set the number for the index to start from.
|
|
405
436
|
Default value is 1.
|
|
406
437
|
column_delimiter : str
|
|
407
|
-
Character to delimit the columns, applying both for the header and the content.
|
|
408
|
-
|
|
438
|
+
Character to delimit the columns, applying both for the header and the content.
|
|
409
439
|
|
|
410
440
|
Raises
|
|
411
441
|
------
|
|
@@ -459,7 +489,7 @@ def format_table_from_list(dict_list,
|
|
|
459
489
|
|
|
460
490
|
# Build the header string
|
|
461
491
|
header_row = column_delimiter + \
|
|
462
|
-
column_delimiter.join(
|
|
492
|
+
column_delimiter.join(header.center(column_widths[header])
|
|
463
493
|
for header in headers) + \
|
|
464
494
|
column_delimiter
|
|
465
495
|
|
|
@@ -474,13 +504,13 @@ def format_table_from_list(dict_list,
|
|
|
474
504
|
content_rows = []
|
|
475
505
|
for idx, subdict in enumerate(dict_list, start=custom_start_index):
|
|
476
506
|
if display_index:
|
|
477
|
-
row = [
|
|
507
|
+
row = [str(idx).center(column_widths[index_header])]
|
|
478
508
|
else:
|
|
479
509
|
row = []
|
|
480
510
|
for key in keys:
|
|
481
511
|
original_key = list(subdict.keys())[keys.index(key)]
|
|
482
512
|
value = subdict.get(original_key, "")
|
|
483
|
-
row.append(
|
|
513
|
+
row.append(str(value).center(column_widths[key]))
|
|
484
514
|
content_rows.append(column_delimiter + column_delimiter.join(row) + column_delimiter)
|
|
485
515
|
|
|
486
516
|
# Combine all parts
|
|
@@ -488,16 +518,10 @@ def format_table_from_list(dict_list,
|
|
|
488
518
|
return table
|
|
489
519
|
|
|
490
520
|
# # Example usage
|
|
491
|
-
# # dict_list = [
|
|
492
|
-
# # {'key1': 'val11', 'key2': 'val12'},
|
|
493
|
-
# # {'key1': 'val21', 'key2': 'val22'},
|
|
494
|
-
# # {'key1': 'val31', 'key2': 'val32'}
|
|
495
|
-
# # ]
|
|
496
|
-
|
|
497
521
|
# dict_list = [
|
|
498
|
-
# {'
|
|
499
|
-
# {'
|
|
500
|
-
# {'
|
|
522
|
+
# {'key1': 'val11', 'key2': 'val12'},
|
|
523
|
+
# {'key1': 'val21', 'key2': 'val22'},
|
|
524
|
+
# {'key1': 'val31', 'key2': 'val32'}
|
|
501
525
|
# ]
|
|
502
526
|
|
|
503
527
|
# # Print the table with the index
|
|
@@ -510,7 +534,7 @@ def format_table_from_list(dict_list,
|
|
|
510
534
|
|
|
511
535
|
# # Print the table with custom headers
|
|
512
536
|
# custom_keys = ['Futbola', 'Esku pilota edo pala']
|
|
513
|
-
# print(format_table_from_list(dict_list, keys=custom_keys, display_index=
|
|
537
|
+
# print(format_table_from_list(dict_list, keys=custom_keys, display_index=False))
|
|
514
538
|
|
|
515
539
|
|
|
516
540
|
def format_table_from_lists(keys, values,
|
|
@@ -594,7 +618,7 @@ def format_table_from_lists(keys, values,
|
|
|
594
618
|
headers = keys
|
|
595
619
|
|
|
596
620
|
# Build the header string
|
|
597
|
-
header_row = column_delimiter + column_delimiter.join(
|
|
621
|
+
header_row = column_delimiter + column_delimiter.join(header.center(column_widths[header])
|
|
598
622
|
for header in headers) + column_delimiter
|
|
599
623
|
|
|
600
624
|
# Build the header underline string
|
|
@@ -607,11 +631,11 @@ def format_table_from_lists(keys, values,
|
|
|
607
631
|
content_rows = []
|
|
608
632
|
for idx, row in enumerate(rows, start=custom_start_index):
|
|
609
633
|
if display_index:
|
|
610
|
-
row_content = [
|
|
634
|
+
row_content = [str(idx).center(column_widths[index_header])]
|
|
611
635
|
else:
|
|
612
636
|
row_content = []
|
|
613
637
|
for key, value in zip(keys, row):
|
|
614
|
-
row_content.append(
|
|
638
|
+
row_content.append(str(value).center(column_widths[key]))
|
|
615
639
|
content_rows.append(column_delimiter + column_delimiter.join(row_content) + column_delimiter)
|
|
616
640
|
|
|
617
641
|
# Combine all parts
|
|
@@ -642,8 +666,5 @@ MAIN_INPUT_DTYPE_LIST_STRFMT = ["list", "ndarray", "tuple"]
|
|
|
642
666
|
# Error strings #
|
|
643
667
|
TYPE_ERROR_STR1 = "Check the iterable type passed to the instance."
|
|
644
668
|
TYPE_ERROR_STR2 = "Argument must be of type 'str' only."
|
|
645
|
-
|
|
646
669
|
INDEX_ERROR_STR = "Not all indices were referenced in the string to format."
|
|
647
|
-
|
|
648
|
-
SYNTAX_ERROR_STR = "One or more arguments in the formatting object "\
|
|
649
|
-
"has strings with unclosed quotes."
|
|
670
|
+
SYNTAX_ERROR_STR = "One or more arguments in the formatting object has strings with unclosed quotes."
|
|
@@ -10,7 +10,6 @@ import time
|
|
|
10
10
|
from datetime import datetime
|
|
11
11
|
|
|
12
12
|
# Third-party modules #
|
|
13
|
-
import arrow
|
|
14
13
|
import numpy as np
|
|
15
14
|
import pandas as pd
|
|
16
15
|
from dateutil import parser
|
|
@@ -113,6 +112,35 @@ def _validate_unit(unit, module):
|
|
|
113
112
|
raise ValueError("Unsupported date unit for pandas.Timestamp objects. "
|
|
114
113
|
f"Choose one from {PANDAS_DATE_UNIT_LIST}.")
|
|
115
114
|
|
|
115
|
+
# %% UTILITY FUNCTIONS
|
|
116
|
+
|
|
117
|
+
def _arrow_get_with_import(*args, **kwargs):
|
|
118
|
+
"""
|
|
119
|
+
Helper function to import arrow and call arrow.get() with lazy import.
|
|
120
|
+
|
|
121
|
+
Parameters
|
|
122
|
+
----------
|
|
123
|
+
*args : Any
|
|
124
|
+
Arguments to pass to arrow.get()
|
|
125
|
+
**kwargs : Any
|
|
126
|
+
Keyword arguments to pass to arrow.get()
|
|
127
|
+
|
|
128
|
+
Returns
|
|
129
|
+
-------
|
|
130
|
+
arrow.Arrow
|
|
131
|
+
The result of arrow.get(*args, **kwargs)
|
|
132
|
+
|
|
133
|
+
Raises
|
|
134
|
+
------
|
|
135
|
+
ImportError
|
|
136
|
+
If arrow package is not installed
|
|
137
|
+
"""
|
|
138
|
+
try:
|
|
139
|
+
import arrow
|
|
140
|
+
except ImportError:
|
|
141
|
+
raise ImportError("arrow package is required for arrow operations. Install with: pip install arrow")
|
|
142
|
+
|
|
143
|
+
return arrow.get(*args, **kwargs)
|
|
116
144
|
|
|
117
145
|
# %% SIMPLE DATA PARSING
|
|
118
146
|
|
|
@@ -943,6 +971,11 @@ def _to_arrow(dt_obj):
|
|
|
943
971
|
arrow.Arrow
|
|
944
972
|
The converted Arrow object.
|
|
945
973
|
"""
|
|
974
|
+
try:
|
|
975
|
+
import arrow
|
|
976
|
+
except ImportError:
|
|
977
|
+
raise ImportError("arrow package is required for arrow conversion. Install with: pip install arrow")
|
|
978
|
+
|
|
946
979
|
dt_obj = _to_datetime(dt_obj)
|
|
947
980
|
return arrow.get(dt_obj)
|
|
948
981
|
|
|
@@ -967,7 +1000,7 @@ TIME_STR_PARSING_DICT = {
|
|
|
967
1000
|
"dateutil" : lambda datetime_str, dt_fmt_str: parser.parse(datetime_str, dt_fmt_str),
|
|
968
1001
|
"pandas" : lambda datetime_str, dt_fmt_str, _ : pd.to_datetime(datetime_str, format=dt_fmt_str),
|
|
969
1002
|
"numpy" : lambda datetime_str, _, unit : np.datetime64(datetime_str, unit),
|
|
970
|
-
"arrow" : lambda datetime_str, dt_fmt_str:
|
|
1003
|
+
"arrow" : lambda datetime_str, dt_fmt_str: _arrow_get_with_import(datetime_str, dt_fmt_str)
|
|
971
1004
|
}
|
|
972
1005
|
|
|
973
1006
|
# Floated #
|
|
@@ -978,7 +1011,7 @@ FLOATED_TIME_PARSING_DICT = {
|
|
|
978
1011
|
"time" : lambda floated_time : datetime(*tuple(time.localtime(floated_time))[:6]),
|
|
979
1012
|
"pandas" : lambda floated_time, unit : pd.to_datetime(floated_time, unit=unit),
|
|
980
1013
|
"numpy" : lambda floated_time, unit : np.datetime64(floated_time, unit),
|
|
981
|
-
"arrow" : lambda floated_time, _ :
|
|
1014
|
+
"arrow" : lambda floated_time, _ : _arrow_get_with_import(floated_time)
|
|
982
1015
|
}
|
|
983
1016
|
|
|
984
1017
|
# Complex data #
|
|
@@ -990,7 +1023,7 @@ DT_OBJ_CONVERSION_DICT = {
|
|
|
990
1023
|
"time" : lambda dt_obj, _ : dt_obj.timetuple(),
|
|
991
1024
|
"pandas" : lambda dt_obj, unit, _ : pd.to_datetime(_tzinfo_remover(dt_obj), unit=unit),
|
|
992
1025
|
"numpy" : lambda dt_obj, unit, _ : np.datetime64(_tzinfo_remover(dt_obj), unit),
|
|
993
|
-
"arrow" : lambda dt_obj, _ :
|
|
1026
|
+
"arrow" : lambda dt_obj, _ : _arrow_get_with_import(dt_obj),
|
|
994
1027
|
"str" : lambda dt_obj, _, dt_fmt_str : _to_string(dt_obj, dt_fmt_str)
|
|
995
1028
|
}
|
|
996
1029
|
|
|
@@ -14,7 +14,6 @@ import time
|
|
|
14
14
|
from datetime import datetime, timedelta
|
|
15
15
|
|
|
16
16
|
# Third-party modules #
|
|
17
|
-
import arrow
|
|
18
17
|
import numpy as np
|
|
19
18
|
import pandas as pd
|
|
20
19
|
|
|
@@ -124,6 +123,10 @@ def _convert_floated_time_to_datetime(floated_time, module):
|
|
|
124
123
|
elif module == "numpy":
|
|
125
124
|
dt = pd.Timestamp.fromtimestamp(seconds).to_pydatetime() # Convert via pandas for compatibility
|
|
126
125
|
elif module == "arrow":
|
|
126
|
+
try:
|
|
127
|
+
import arrow
|
|
128
|
+
except ImportError:
|
|
129
|
+
raise ImportError("arrow package is required for arrow module conversion. Install with: pip install arrow")
|
|
127
130
|
dt = arrow.get(seconds).datetime
|
|
128
131
|
elif module == "time":
|
|
129
132
|
dt = datetime.fromtimestamp(seconds) # time module uses same as datetime
|
|
@@ -232,7 +235,8 @@ def datetime_obj_converter(datetime_obj,
|
|
|
232
235
|
return datetime_obj.to_pydatetime()
|
|
233
236
|
if isinstance(datetime_obj, np.datetime64):
|
|
234
237
|
return pd.Timestamp(datetime_obj).to_pydatetime()
|
|
235
|
-
if
|
|
238
|
+
# Check if the object is an Arrow object using string comparison to avoid import
|
|
239
|
+
if obj_type == "arrow":
|
|
236
240
|
return datetime_obj.datetime
|
|
237
241
|
raise ValueError(f"Cannot convert {obj_type} to datetime")
|
|
238
242
|
|
|
@@ -244,7 +248,7 @@ def datetime_obj_converter(datetime_obj,
|
|
|
244
248
|
return pd.Timestamp(datetime_obj)
|
|
245
249
|
if isinstance(datetime_obj, np.datetime64):
|
|
246
250
|
return pd.Timestamp(datetime_obj, unit=unit)
|
|
247
|
-
if
|
|
251
|
+
if obj_type == "arrow":
|
|
248
252
|
return pd.Timestamp(datetime_obj.datetime)
|
|
249
253
|
raise ValueError(f"Cannot convert {obj_type} to Timestamp")
|
|
250
254
|
|
|
@@ -254,13 +258,18 @@ def datetime_obj_converter(datetime_obj,
|
|
|
254
258
|
return datetime_obj.astype(f'datetime64[{unit}]')
|
|
255
259
|
if isinstance(datetime_obj, (datetime, pd.Timestamp)):
|
|
256
260
|
return np.datetime64(datetime_obj, unit)
|
|
257
|
-
if
|
|
261
|
+
if obj_type == "arrow":
|
|
258
262
|
return np.datetime64(datetime_obj.datetime, unit)
|
|
259
263
|
raise ValueError(f"Cannot convert {obj_type} to datetime64")
|
|
260
264
|
|
|
261
265
|
# Convert to arrow if requested
|
|
262
266
|
if convert_to == "arrow":
|
|
263
|
-
|
|
267
|
+
try:
|
|
268
|
+
import arrow
|
|
269
|
+
except ImportError:
|
|
270
|
+
raise ImportError("arrow package is required for arrow conversion. Install with: pip install arrow")
|
|
271
|
+
|
|
272
|
+
if obj_type == "arrow":
|
|
264
273
|
return datetime_obj
|
|
265
274
|
if isinstance(datetime_obj, datetime):
|
|
266
275
|
return arrow.get(datetime_obj)
|
|
@@ -279,7 +288,7 @@ def datetime_obj_converter(datetime_obj,
|
|
|
279
288
|
# For numpy datetime64 objects
|
|
280
289
|
timestamp = datetime_obj.astype(f'datetime64[{unit}]').astype(float_class)
|
|
281
290
|
return timestamp
|
|
282
|
-
elif
|
|
291
|
+
elif obj_type == "arrow":
|
|
283
292
|
timestamp = datetime_obj.float_timestamp
|
|
284
293
|
else:
|
|
285
294
|
raise ValueError(f"Cannot convert {obj_type} to float")
|
|
@@ -303,7 +312,7 @@ def datetime_obj_converter(datetime_obj,
|
|
|
303
312
|
# For numpy datetime64 objects
|
|
304
313
|
timestamp = datetime_obj.astype(f'datetime64[{unit}]').astype(int_class)
|
|
305
314
|
return timestamp
|
|
306
|
-
elif
|
|
315
|
+
elif obj_type == "arrow":
|
|
307
316
|
timestamp = int(datetime_obj.float_timestamp)
|
|
308
317
|
else:
|
|
309
318
|
raise ValueError(f"Cannot convert {obj_type} to int")
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pygenutils
|
|
3
|
-
Version: 16.
|
|
3
|
+
Version: 16.2.0
|
|
4
4
|
Summary: A comprehensive Python utility library for general-purpose and specialised tasks
|
|
5
5
|
Author-email: Jon Ander Gabantxo <jagabantxo@gmail.com>
|
|
6
6
|
License: MIT License
|
|
@@ -47,9 +47,10 @@ Requires-Dist: numpy<2.0.0,>=1.21.0
|
|
|
47
47
|
Requires-Dist: pandas<2.0.0,>=1.3.0
|
|
48
48
|
Requires-Dist: filewise>=3.11.0
|
|
49
49
|
Requires-Dist: paramlib>=3.4.3
|
|
50
|
-
Requires-Dist: arrow>=1.2.0
|
|
51
50
|
Provides-Extra: xarray
|
|
52
51
|
Requires-Dist: xarray>=2024.2.0; extra == "xarray"
|
|
52
|
+
Provides-Extra: arrow
|
|
53
|
+
Requires-Dist: arrow>=1.2.0; extra == "arrow"
|
|
53
54
|
Provides-Extra: dev
|
|
54
55
|
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
55
56
|
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
@@ -117,11 +118,17 @@ This package has minimal external dependencies and is designed to be lightweight
|
|
|
117
118
|
**For regular users** who want to use the package in their projects:
|
|
118
119
|
|
|
119
120
|
```bash
|
|
120
|
-
pip install pygenutils
|
|
121
|
+
pip install pygenutils # Core functionality
|
|
122
|
+
pip install pygenutils[arrow] # With arrow support (optional)
|
|
121
123
|
```
|
|
122
124
|
|
|
123
125
|
This automatically installs `pygenutils` and all its dependencies with version constraints.
|
|
124
126
|
|
|
127
|
+
**How It Works Now**:
|
|
128
|
+
|
|
129
|
+
- `pip install pygenutils` - Core functionality without arrow dependency
|
|
130
|
+
- `pip install pygenutils[arrow]` - With arrow support for enhanced time handling features
|
|
131
|
+
|
|
125
132
|
### Package Updates
|
|
126
133
|
|
|
127
134
|
To stay up-to-date with the latest version of this package, simply run:
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "pygenutils"
|
|
7
|
-
version = "16.
|
|
7
|
+
version = "16.2.0"
|
|
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"]
|
|
@@ -31,11 +31,11 @@ dependencies = [
|
|
|
31
31
|
"pandas>=1.3.0,<2.0.0",
|
|
32
32
|
"filewise>=3.11.0",
|
|
33
33
|
"paramlib>=3.4.3",
|
|
34
|
-
"arrow>=1.2.0",
|
|
35
34
|
]
|
|
36
35
|
|
|
37
36
|
[project.optional-dependencies]
|
|
38
37
|
xarray = ["xarray>=2024.2.0"]
|
|
38
|
+
arrow = ["arrow>=1.2.0"]
|
|
39
39
|
dev = [
|
|
40
40
|
"pytest>=7.0.0",
|
|
41
41
|
"pytest-cov>=4.0.0",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pygenutils-16.1.3 → pygenutils-16.2.0}/pygenutils/audio_and_video/audio_and_video_manipulation.py
RENAMED
|
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
|
{pygenutils-16.1.3 → pygenutils-16.2.0}/pygenutils/time_handling/program_snippet_exec_timers.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|