dukit 0.2.3__tar.gz → 0.2.4__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.
- {dukit-0.2.3 → dukit-0.2.4}/PKG-INFO +1 -1
- {dukit-0.2.3 → dukit-0.2.4}/pyproject.toml +1 -1
- {dukit-0.2.3 → dukit-0.2.4}/src/dukit/excel.py +1 -1
- {dukit-0.2.3 → dukit-0.2.4}/src/dukit/os.py +1 -1
- {dukit-0.2.3 → dukit-0.2.4}/src/dukit/pandas.py +13 -31
- {dukit-0.2.3 → dukit-0.2.4}/src/dukit/qlang/symbols.py +1 -0
- {dukit-0.2.3 → dukit-0.2.4}/src/dukit/typing.py +2 -2
- {dukit-0.2.3 → dukit-0.2.4}/src/dukit/utils.py +1 -1
- {dukit-0.2.3 → dukit-0.2.4}/README.md +0 -0
- {dukit-0.2.3 → dukit-0.2.4}/src/dukit/__init__.py +0 -0
- {dukit-0.2.3 → dukit-0.2.4}/src/dukit/_test_utils.py +0 -0
- {dukit-0.2.3 → dukit-0.2.4}/src/dukit/diffing.py +0 -0
- {dukit-0.2.3 → dukit-0.2.4}/src/dukit/interfaces.py +0 -0
- {dukit-0.2.3 → dukit-0.2.4}/src/dukit/py.typed +0 -0
- {dukit-0.2.3 → dukit-0.2.4}/src/dukit/qlang/__init__.py +0 -0
- {dukit-0.2.3 → dukit-0.2.4}/src/dukit/qlang/engine.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "dukit"
|
|
3
|
-
version = "0.2.
|
|
3
|
+
version = "0.2.4"
|
|
4
4
|
description = "dukit - data utilities kit for exploring, modifying and visualizing small but messy data using pandas"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
authors = [{ name = "MartinVoelkl94", email = "martinv16248@gmail.com" }]
|
|
@@ -20,7 +20,7 @@ def format(
|
|
|
20
20
|
align_horizontal='left',
|
|
21
21
|
wrap_text=True,
|
|
22
22
|
verbosity=3,
|
|
23
|
-
):
|
|
23
|
+
):
|
|
24
24
|
"""
|
|
25
25
|
applies formatting to an Excel file:
|
|
26
26
|
- adjust col width to max length of cell content (accounts for linebreaks)
|
|
@@ -262,7 +262,7 @@ def fetch(path, before='now', verbosity=3):
|
|
|
262
262
|
timestamp = datetime_(timestamp_str)
|
|
263
263
|
if timestamp < datetime_(cutoff):
|
|
264
264
|
timestamps[timestamp] = (timestamp_str, extension)
|
|
265
|
-
except Exception:
|
|
265
|
+
except Exception:
|
|
266
266
|
pass
|
|
267
267
|
if len(timestamps) == 0:
|
|
268
268
|
text = (
|
|
@@ -544,19 +544,13 @@ def date_delta(
|
|
|
544
544
|
else:
|
|
545
545
|
df['reference_date'] = df[reference_col].apply(date_)
|
|
546
546
|
|
|
547
|
-
cols_reorder = [
|
|
548
|
-
cols_reorder += [
|
|
549
|
-
col
|
|
550
|
-
for col
|
|
551
|
-
in df.columns
|
|
552
|
-
if col != 'reference_date'
|
|
553
|
-
]
|
|
547
|
+
cols_reorder = [col for col in df.columns]
|
|
554
548
|
df = df[cols_reorder]
|
|
555
549
|
|
|
556
550
|
for col in df.columns:
|
|
557
551
|
if col not in cols_dates:
|
|
558
552
|
continue
|
|
559
|
-
if col
|
|
553
|
+
if col in ['reference_date', reference_col]:
|
|
560
554
|
continue
|
|
561
555
|
|
|
562
556
|
name = f'days from{linebreak}{reference_col}{linebreak}to{linebreak}{col}'
|
|
@@ -586,13 +580,12 @@ def _fix_nas(x):
|
|
|
586
580
|
|
|
587
581
|
def date_table(
|
|
588
582
|
df: pd.DataFrame,
|
|
589
|
-
reference_date: str | datetime.date | pd.Timestamp = None,
|
|
590
583
|
reference_col: str = None,
|
|
591
584
|
uid: str = None,
|
|
592
585
|
upper: int = None,
|
|
593
586
|
lower: int = None,
|
|
594
587
|
start_at_day1: bool = True,
|
|
595
|
-
schedule: dict = None,
|
|
588
|
+
schedule: dict[int, str] = None,
|
|
596
589
|
linebreak: str = '\n',
|
|
597
590
|
verbosity: int = 3,
|
|
598
591
|
) -> pd.DataFrame | pd.io.formats.style.Styler:
|
|
@@ -602,28 +595,15 @@ def date_table(
|
|
|
602
595
|
reference date or column.
|
|
603
596
|
"""
|
|
604
597
|
|
|
605
|
-
if
|
|
606
|
-
msg = 'ERROR: no reference
|
|
598
|
+
if reference_col is None:
|
|
599
|
+
msg = 'ERROR: no reference column provided'
|
|
607
600
|
log(msg, 'dk.date_delta', verbosity)
|
|
608
|
-
return
|
|
609
|
-
|
|
610
|
-
if reference_date is not None and reference_col is not None:
|
|
611
|
-
msg = 'ERROR: both reference date and column provided'
|
|
612
|
-
log(msg, 'dk.date_delta', verbosity)
|
|
613
|
-
return df
|
|
601
|
+
return pd.DataFrame()
|
|
614
602
|
|
|
615
603
|
df = df.copy()
|
|
616
|
-
|
|
617
604
|
if uid:
|
|
618
605
|
df.index = df[uid]
|
|
619
|
-
|
|
620
|
-
if reference_date is not None:
|
|
621
|
-
reference = pd.Series(
|
|
622
|
-
date_(reference_date),
|
|
623
|
-
index=df.index
|
|
624
|
-
)
|
|
625
|
-
else:
|
|
626
|
-
reference = df[reference_col].apply(date_)
|
|
606
|
+
reference = df[reference_col].apply(date_)
|
|
627
607
|
|
|
628
608
|
df = (
|
|
629
609
|
df
|
|
@@ -659,20 +639,22 @@ def date_table(
|
|
|
659
639
|
|
|
660
640
|
|
|
661
641
|
if upper is None:
|
|
662
|
-
upper = int(deltas.max().max())
|
|
642
|
+
upper = int(deltas.max().max()) + 1
|
|
663
643
|
if lower is None:
|
|
664
644
|
lower = int(deltas.min().min())
|
|
665
645
|
|
|
666
646
|
days = list(range(lower, upper + 1))
|
|
667
647
|
if start_at_day1:
|
|
668
648
|
days.remove(0)
|
|
649
|
+
else:
|
|
650
|
+
days.pop(-1)
|
|
669
651
|
days_df = pd.DataFrame({'days': days})
|
|
670
652
|
|
|
671
653
|
df_timeline = days_df.copy()
|
|
672
654
|
if schedule is not None:
|
|
673
655
|
df_schedule = pd.DataFrame({
|
|
674
|
-
'days': list(schedule.
|
|
675
|
-
'planned': list(schedule.
|
|
656
|
+
'days': list(schedule.keys()),
|
|
657
|
+
'planned': list(schedule.values()),
|
|
676
658
|
})
|
|
677
659
|
df_timeline = df_timeline.merge(
|
|
678
660
|
df_schedule,
|
|
@@ -722,7 +704,7 @@ def _highlight_schedule(
|
|
|
722
704
|
schedule: dict,
|
|
723
705
|
) -> pd.io.formats.style.Styler:
|
|
724
706
|
|
|
725
|
-
days_highlight = list(schedule.
|
|
707
|
+
days_highlight = list(schedule.keys())
|
|
726
708
|
|
|
727
709
|
df_style = pd.DataFrame(
|
|
728
710
|
'text-align: left;',
|
|
@@ -300,7 +300,7 @@ def date_(x, errors='coerce', na=pd.NaT) -> typing.Any:
|
|
|
300
300
|
return result.date()
|
|
301
301
|
|
|
302
302
|
#raise and coerce are handled in _datetime and should not be reached here
|
|
303
|
-
elif errors == 'raise':
|
|
303
|
+
elif errors == 'raise':
|
|
304
304
|
raise ValueError(
|
|
305
305
|
f'could not convert "{x}" to datetime.\n'
|
|
306
306
|
'Error handling:\n'
|
|
@@ -312,7 +312,7 @@ def date_(x, errors='coerce', na=pd.NaT) -> typing.Any:
|
|
|
312
312
|
elif errors == 'ignore':
|
|
313
313
|
return x
|
|
314
314
|
elif errors == 'coerce':
|
|
315
|
-
return na
|
|
315
|
+
return na
|
|
316
316
|
else:
|
|
317
317
|
return errors
|
|
318
318
|
|
|
@@ -164,7 +164,7 @@ def log(
|
|
|
164
164
|
logs.append(message)
|
|
165
165
|
|
|
166
166
|
#for jupyter
|
|
167
|
-
if get_ipython().__class__.__name__ == 'ZMQInteractiveShell':
|
|
167
|
+
if get_ipython().__class__.__name__ == 'ZMQInteractiveShell':
|
|
168
168
|
|
|
169
169
|
#make html friendly
|
|
170
170
|
message['text'] = (
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|