dukit 0.1.0__py3-none-any.whl

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/__init__.py ADDED
@@ -0,0 +1,108 @@
1
+
2
+ from .utils import (
3
+ log,
4
+ )
5
+ from .diffing import (
6
+ diff,
7
+ rediff,
8
+ )
9
+ from . import qlang
10
+ from .qlang import (
11
+ q,
12
+ qr,
13
+ qs,
14
+ )
15
+ from .interfaces import (
16
+ DukitAccessor,
17
+ )
18
+ from .pandas import (
19
+ get_df,
20
+ get_dfs,
21
+ deduplicate,
22
+ flatten,
23
+ stagger,
24
+ embed,
25
+ collapse,
26
+ transpose,
27
+ date_delta,
28
+ )
29
+ from .excel import (
30
+ format,
31
+ save,
32
+ )
33
+ from .typing import (
34
+ Box,
35
+ str_ as str,
36
+ int_ as int,
37
+ float_ as float,
38
+ num_ as num,
39
+ bool_ as bool,
40
+ date_ as date,
41
+ datetime_ as datetime,
42
+ na_ as na,
43
+ nk_ as nk,
44
+ yn_ as yn,
45
+ type_ as type,
46
+ convert_ as convert,
47
+ typeinfo_ as typeinfo,
48
+ typeinfostrict_ as typeinfostrict,
49
+ list_ as list,
50
+ )
51
+ from .os import (
52
+ pwd,
53
+ cd,
54
+ cp,
55
+ mv,
56
+ mkdir,
57
+ isdir,
58
+ isfile,
59
+ ispath,
60
+ fetch,
61
+ )
62
+
63
+ __all__ = (
64
+ 'log',
65
+ 'diff',
66
+ 'rediff',
67
+ 'qlang',
68
+ 'q',
69
+ 'qr',
70
+ 'qs',
71
+ 'DukitAccessor',
72
+ 'get_df',
73
+ 'get_dfs',
74
+ 'deduplicate',
75
+ 'flatten',
76
+ 'stagger',
77
+ 'embed',
78
+ 'collapse',
79
+ 'transpose',
80
+ 'date_delta',
81
+ 'format',
82
+ 'save',
83
+ 'Box',
84
+ 'str',
85
+ 'int',
86
+ 'float',
87
+ 'num',
88
+ 'bool',
89
+ 'date',
90
+ 'datetime',
91
+ 'na',
92
+ 'nk',
93
+ 'yn',
94
+ 'type',
95
+ 'convert',
96
+ 'typeinfo',
97
+ 'typeinfostrict',
98
+ 'list',
99
+ 'pwd',
100
+ 'cd',
101
+ 'cp',
102
+ 'mv',
103
+ 'mkdir',
104
+ 'isdir',
105
+ 'isfile',
106
+ 'ispath',
107
+ 'fetch',
108
+ )
dukit/_test_utils.py ADDED
@@ -0,0 +1,374 @@
1
+
2
+ import pandas as pd
3
+ from .utils import (
4
+ GREEN,
5
+ RED,
6
+ GREEN_LIGHT,
7
+ ORANGE_LIGHT,
8
+ RED_LIGHT,
9
+ )
10
+
11
+
12
+ def _setup_csv(df_old, df_new, tmpdir):
13
+
14
+ path_df_old = f'{tmpdir}/df_old.csv'
15
+ df_old.to_csv(path_df_old, index=False)
16
+
17
+ path_df_new = f'{tmpdir}/df_new.csv'
18
+ df_new.to_csv(path_df_new, index=False)
19
+
20
+ return path_df_old, path_df_new
21
+
22
+
23
+ def _setup_xlsx(df_old, df_new, tmpdir):
24
+
25
+ path_df_old = f'{tmpdir}/df_old.xlsx'
26
+ df_old.to_excel(path_df_old, index=False)
27
+
28
+ path_df_new = f'{tmpdir}/df_new.xlsx'
29
+ df_new.to_excel(path_df_new, index=False)
30
+
31
+ return path_df_old, path_df_new
32
+
33
+
34
+
35
+ def _get_dfs():
36
+
37
+ df_old = pd.DataFrame(
38
+ columns=['a', 'b', 'c'],
39
+ index=['x', 'y', 'z', ],
40
+ )
41
+
42
+ df_old.insert(0, 'uid', df_old.index)
43
+
44
+ df_old.loc['x', 'a'] = 1
45
+ df_old.loc['x', 'b'] = 1
46
+ df_old.loc['x', 'c'] = 1
47
+
48
+ df_old.loc['y', 'a'] = 2
49
+ df_old.loc['y', 'b'] = 2
50
+ df_old.loc['y', 'c'] = 2
51
+
52
+ df_old.loc['z', 'a'] = 3
53
+ df_old.loc['z', 'b'] = None
54
+ df_old.loc['z', 'c'] = 3
55
+
56
+
57
+ df_new = pd.DataFrame(
58
+ columns=['d', 'b', 'a'],
59
+ index=['y', 'x2', 'z', ],
60
+ )
61
+
62
+ df_new.insert(0, 'uid', df_new.index)
63
+
64
+ df_new.loc['y', 'd'] = 2
65
+ df_new.loc['y', 'b'] = 2
66
+ df_new.loc['y', 'a'] = 0
67
+
68
+ df_new.loc['x2', 'd'] = 1
69
+ df_new.loc['x2', 'b'] = 1
70
+ df_new.loc['x2', 'a'] = 1
71
+
72
+ df_new.loc['z', 'd'] = 3
73
+ df_new.loc['z', 'b'] = 3
74
+ df_new.loc['z', 'a'] = pd.NA
75
+
76
+ return df_old, df_new
77
+
78
+
79
+
80
+ def _get_expected_new():
81
+
82
+ uid = pd.Series(
83
+ ['y', 'x2', 'z'],
84
+ dtype='string',
85
+ name='uid',
86
+ )
87
+ expected = pd.DataFrame(
88
+ columns=['uid', 'diff', 'd', 'b', 'a'],
89
+ index=uid,
90
+ )
91
+
92
+ expected['uid'] = expected.index
93
+
94
+ expected.loc['y', 'diff'] = 'vals changed: 1'
95
+ expected.loc['x2', 'diff'] = 'row added'
96
+ expected.loc['z', 'diff'] = 'vals added: 1<br>vals removed: 1'
97
+
98
+ expected.loc['y', 'd'] = 2
99
+ expected.loc['x2', 'd'] = 1
100
+ expected.loc['z', 'd'] = 3
101
+
102
+ expected.loc['y', 'b'] = 2
103
+ expected.loc['x2', 'b'] = 1
104
+ expected.loc['z', 'b'] = 3
105
+
106
+ expected.loc['y', 'a'] = 0
107
+ expected.loc['x2', 'a'] = 1
108
+ expected.loc['z', 'a'] = pd.NA
109
+
110
+ expected.reset_index(drop=True, inplace=True)
111
+
112
+ return expected.convert_dtypes()
113
+
114
+
115
+ def _get_expected_newplus():
116
+
117
+ uid = pd.Series(
118
+ ['y', 'x2', 'z'],
119
+ dtype='string',
120
+ name='uid',
121
+ )
122
+ expected = pd.DataFrame(
123
+ columns=['uid', 'diff', 'd', 'b', 'b *old', 'a', 'a *old'],
124
+ index=uid,
125
+ )
126
+
127
+ expected['uid'] = expected.index
128
+
129
+ expected.loc['y', 'diff'] = 'vals changed: 1'
130
+ expected.loc['x2', 'diff'] = 'row added'
131
+ expected.loc['z', 'diff'] = 'vals added: 1<br>vals removed: 1'
132
+
133
+ expected.loc['y', 'd'] = 2
134
+ expected.loc['x2', 'd'] = 1
135
+ expected.loc['z', 'd'] = 3
136
+
137
+ expected.loc['y', 'b'] = 2
138
+ expected.loc['x2', 'b'] = 1
139
+ expected.loc['z', 'b'] = 3
140
+
141
+ expected.loc['y', 'b *old'] = pd.NA
142
+ expected.loc['x2', 'b *old'] = pd.NA
143
+ expected.loc['z', 'b *old'] = pd.NA
144
+
145
+ expected.loc['y', 'a'] = 0
146
+ expected.loc['x2', 'a'] = 1
147
+ expected.loc['z', 'a'] = pd.NA
148
+
149
+ expected.loc['y', 'a *old'] = 2
150
+ expected.loc['x2', 'a *old'] = pd.NA
151
+ expected.loc['z', 'a *old'] = 3
152
+
153
+ expected['b *old'] = expected['b *old'].astype('Int64')
154
+ expected.reset_index(drop=True, inplace=True)
155
+
156
+ return expected.convert_dtypes()
157
+
158
+
159
+ def _get_expected_old():
160
+
161
+ uid = pd.Series(
162
+ ['x', 'y', 'z'],
163
+ dtype='string',
164
+ name='uid',
165
+ )
166
+ expected = pd.DataFrame(
167
+ columns=['uid', 'diff', 'a', 'b', 'c'],
168
+ index=uid,
169
+ )
170
+
171
+ expected['uid'] = expected.index
172
+
173
+ expected.loc['x', 'diff'] = 'row removed'
174
+ expected.loc['y', 'diff'] = 'vals changed: 1'
175
+ expected.loc['z', 'diff'] = 'vals added: 1<br>vals removed: 1'
176
+
177
+ expected.loc['x', 'a'] = 1
178
+ expected.loc['y', 'a'] = 2
179
+ expected.loc['z', 'a'] = 3
180
+
181
+ expected.loc['x', 'b'] = 1
182
+ expected.loc['y', 'b'] = 2
183
+ expected.loc['z', 'b'] = pd.NA
184
+
185
+ expected.loc['x', 'c'] = 1
186
+ expected.loc['y', 'c'] = 2
187
+ expected.loc['z', 'c'] = 3
188
+
189
+ expected.reset_index(drop=True, inplace=True)
190
+
191
+ return expected.convert_dtypes()
192
+
193
+
194
+ def _get_expected_mix():
195
+
196
+ uid = pd.Series(
197
+ ['y', 'x2', 'z', 'x'],
198
+ dtype='string',
199
+ name='uid',
200
+ )
201
+ expected = pd.DataFrame(
202
+ columns=['uid', 'diff', 'd', 'b', 'a', 'c'],
203
+ index=uid,
204
+ )
205
+
206
+ expected['uid'] = expected.index
207
+
208
+ expected.loc['y', 'diff'] = 'vals changed: 1'
209
+ expected.loc['x2', 'diff'] = 'row added'
210
+ expected.loc['z', 'diff'] = 'vals added: 1<br>vals removed: 1'
211
+ expected.loc['x', 'diff'] = 'row removed'
212
+
213
+ expected.loc['y', 'd'] = 2
214
+ expected.loc['x2', 'd'] = 1
215
+ expected.loc['z', 'd'] = 3
216
+ expected.loc['x', 'd'] = pd.NA
217
+
218
+ expected.loc['y', 'b'] = 2
219
+ expected.loc['x2', 'b'] = 1
220
+ expected.loc['z', 'b'] = 3
221
+ expected.loc['x', 'b'] = 1
222
+
223
+
224
+ expected.loc['y', 'a'] = 0
225
+ expected.loc['x2', 'a'] = 1
226
+ expected.loc['z', 'a'] = pd.NA
227
+ expected.loc['x', 'a'] = 1
228
+
229
+ expected.loc['y', 'c'] = 2
230
+ expected.loc['x2', 'c'] = pd.NA
231
+ expected.loc['z', 'c'] = 3
232
+ expected.loc['x', 'c'] = 1
233
+
234
+ expected.reset_index(drop=True, inplace=True)
235
+
236
+ return expected.convert_dtypes()
237
+
238
+
239
+
240
+
241
+ def _get_expected_style_new():
242
+
243
+ uid = pd.Series(
244
+ ['y', 'x2', 'z'],
245
+ dtype='string',
246
+ name='uid',
247
+ )
248
+ expected = pd.DataFrame(
249
+ columns=['d', 'b', 'a'],
250
+ index=uid,
251
+ )
252
+
253
+ expected.loc['y', 'd'] = f'background-color: {GREEN};'
254
+ expected.loc['x2', 'd'] = f'background-color: {GREEN};background-color: {GREEN};'
255
+ expected.loc['z', 'd'] = f'background-color: {GREEN};'
256
+
257
+ expected.loc['y', 'b'] = ''
258
+ expected.loc['x2', 'b'] = f'background-color: {GREEN};'
259
+ expected.loc['z', 'b'] = f'background-color: {GREEN_LIGHT};'
260
+
261
+ expected.loc['y', 'a'] = f'background-color: {ORANGE_LIGHT};'
262
+ expected.loc['x2', 'a'] = f'background-color: {GREEN};'
263
+ expected.loc['z', 'a'] = f'background-color: {RED_LIGHT};'
264
+
265
+ expected.reset_index(drop=True, inplace=True)
266
+
267
+ return expected.convert_dtypes()
268
+
269
+
270
+
271
+ def _get_expected_style_newplus():
272
+
273
+ uid = pd.Series(
274
+ ['y', 'x2', 'z'],
275
+ dtype='string',
276
+ name='uid',
277
+ )
278
+ expected = pd.DataFrame(
279
+ columns=['d', 'b', 'b *old', 'a', 'a *old'],
280
+ index=uid,
281
+ )
282
+
283
+ expected.loc['y', 'd'] = f'background-color: {GREEN};'
284
+ expected.loc['x2', 'd'] = f'background-color: {GREEN};background-color: {GREEN};'
285
+ expected.loc['z', 'd'] = f'background-color: {GREEN};'
286
+
287
+ expected.loc['y', 'b'] = ''
288
+ expected.loc['x2', 'b'] = f'background-color: {GREEN};'
289
+ expected.loc['z', 'b'] = f'background-color: {GREEN_LIGHT};'
290
+
291
+ expected.loc['y', 'b *old'] = 'font-style: italic;'
292
+ expected.loc['x2', 'b *old'] = f'font-style: italic;background-color: {GREEN};'
293
+ expected.loc['z', 'b *old'] = 'font-style: italic;'
294
+
295
+ expected.loc['y', 'a'] = f'background-color: {ORANGE_LIGHT};'
296
+ expected.loc['x2', 'a'] = f'background-color: {GREEN};'
297
+ expected.loc['z', 'a'] = f'background-color: {RED_LIGHT};'
298
+
299
+ expected.loc['y', 'a *old'] = 'font-style: italic;'
300
+ expected.loc['x2', 'a *old'] = f'font-style: italic;background-color: {GREEN};'
301
+ expected.loc['z', 'a *old'] = 'font-style: italic;'
302
+
303
+ expected.reset_index(drop=True, inplace=True)
304
+
305
+ return expected.convert_dtypes()
306
+
307
+
308
+
309
+ def _get_expected_style_old():
310
+
311
+ uid = pd.Series(
312
+ ['x', 'y', 'z'],
313
+ dtype='string',
314
+ name='uid',
315
+ )
316
+ expected = pd.DataFrame(
317
+ columns=['a', 'b', 'c'],
318
+ index=uid,
319
+ )
320
+
321
+ expected.loc['x', 'a'] = f'background-color: {RED};'
322
+ expected.loc['y', 'a'] = f'background-color: {ORANGE_LIGHT};'
323
+ expected.loc['z', 'a'] = f'background-color: {RED_LIGHT};'
324
+
325
+ expected.loc['x', 'b'] = f'background-color: {RED};'
326
+ expected.loc['y', 'b'] = ''
327
+ expected.loc['z', 'b'] = f'background-color: {GREEN_LIGHT};'
328
+
329
+ expected.loc['x', 'c'] = f'background-color: {RED};background-color: {RED};'
330
+ expected.loc['y', 'c'] = f'background-color: {RED};'
331
+ expected.loc['z', 'c'] = f'background-color: {RED};'
332
+
333
+ expected.reset_index(drop=True, inplace=True)
334
+
335
+ return expected.convert_dtypes()
336
+
337
+
338
+
339
+ def _get_expected_style_mix():
340
+
341
+ uid = pd.Series(
342
+ ['y', 'x2', 'z', 'x'],
343
+ dtype='string',
344
+ name='uid',
345
+ )
346
+ expected = pd.DataFrame(
347
+ columns=['d', 'b', 'a', 'c'],
348
+ index=uid,
349
+ )
350
+
351
+ expected.loc['x', 'd'] = f'background-color: {GREEN};background-color: {RED};'
352
+ expected.loc['y', 'd'] = f'background-color: {GREEN};'
353
+ expected.loc['x2', 'd'] = f'background-color: {GREEN};background-color: {GREEN};'
354
+ expected.loc['z', 'd'] = f'background-color: {GREEN};'
355
+
356
+ expected.loc['x', 'b'] = f'background-color: {RED};'
357
+ expected.loc['y', 'b'] = ''
358
+ expected.loc['x2', 'b'] = f'background-color: {GREEN};'
359
+ expected.loc['z', 'b'] = f'background-color: {GREEN_LIGHT};'
360
+
361
+ expected.loc['x', 'a'] = f'background-color: {RED};'
362
+ expected.loc['y', 'a'] = f'background-color: {ORANGE_LIGHT};'
363
+ expected.loc['x2', 'a'] = f'background-color: {GREEN};'
364
+ expected.loc['z', 'a'] = f'background-color: {RED_LIGHT};'
365
+
366
+ expected.loc['x', 'c'] = f'background-color: {RED};background-color: {RED};'
367
+ expected.loc['y', 'c'] = f'background-color: {RED};'
368
+ expected.loc['x2', 'c'] = f'background-color: {GREEN};background-color: {RED};'
369
+ expected.loc['z', 'c'] = f'background-color: {RED};'
370
+
371
+
372
+ expected.reset_index(drop=True, inplace=True)
373
+
374
+ return expected.convert_dtypes()