xlwings-utils 25.0.0__tar.gz → 25.0.0.post0__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.
Potentially problematic release.
This version of xlwings-utils might be problematic. Click here for more details.
- {xlwings_utils-25.0.0 → xlwings_utils-25.0.0.post0}/PKG-INFO +1 -1
- {xlwings_utils-25.0.0 → xlwings_utils-25.0.0.post0}/pyproject.toml +1 -1
- {xlwings_utils-25.0.0 → xlwings_utils-25.0.0.post0}/tests/test_xlwings_utils.py +38 -0
- {xlwings_utils-25.0.0 → xlwings_utils-25.0.0.post0}/xlwings_utils/xlwings_utils.py +68 -19
- {xlwings_utils-25.0.0 → xlwings_utils-25.0.0.post0}/xlwings_utils.egg-info/PKG-INFO +1 -1
- {xlwings_utils-25.0.0 → xlwings_utils-25.0.0.post0}/README.md +0 -0
- {xlwings_utils-25.0.0 → xlwings_utils-25.0.0.post0}/setup.cfg +0 -0
- {xlwings_utils-25.0.0 → xlwings_utils-25.0.0.post0}/xlwings_utils/__init__.py +0 -0
- {xlwings_utils-25.0.0 → xlwings_utils-25.0.0.post0}/xlwings_utils.egg-info/SOURCES.txt +0 -0
- {xlwings_utils-25.0.0 → xlwings_utils-25.0.0.post0}/xlwings_utils.egg-info/dependency_links.txt +0 -0
- {xlwings_utils-25.0.0 → xlwings_utils-25.0.0.post0}/xlwings_utils.egg-info/requires.txt +0 -0
- {xlwings_utils-25.0.0 → xlwings_utils-25.0.0.post0}/xlwings_utils.egg-info/top_level.txt +0 -0
|
@@ -102,6 +102,44 @@ def test_raise():
|
|
|
102
102
|
with pytest.raises(IndexError):
|
|
103
103
|
this_block[1, 7] = 1
|
|
104
104
|
|
|
105
|
+
def test_lookup():
|
|
106
|
+
bl=xwu.block([[1,"One", "Un"],[2, "Two", "Deux"],[3,"Three","Trois"]])
|
|
107
|
+
assert bl.lookup(1)=="One"
|
|
108
|
+
assert bl.lookup(3, column2=3)=="Trois"
|
|
109
|
+
with pytest.raises(ValueError):
|
|
110
|
+
bl.lookup(4)
|
|
111
|
+
with pytest.raises(ValueError):
|
|
112
|
+
bl.lookup(1, column1=4)
|
|
113
|
+
with pytest.raises(ValueError):
|
|
114
|
+
bl.lookup(1, column1=3)
|
|
115
|
+
assert bl.lookup_row(1)==1
|
|
116
|
+
assert bl.lookup_row(3)==3
|
|
117
|
+
|
|
118
|
+
def test_vookup():
|
|
119
|
+
bl=xwu.block([[1,"One", "Un"],[2, "Two", "Deux"],[3,"Three","Trois"]])
|
|
120
|
+
assert bl.vlookup(1)=="One"
|
|
121
|
+
assert bl.vlookup(3, column2=3)=="Trois"
|
|
122
|
+
with pytest.raises(ValueError):
|
|
123
|
+
bl.vlookup(4)
|
|
124
|
+
with pytest.raises(ValueError):
|
|
125
|
+
bl.vlookup(1, column1=4)
|
|
126
|
+
with pytest.raises(ValueError):
|
|
127
|
+
bl.vlookup(1, column1=3)
|
|
128
|
+
|
|
129
|
+
def test_hlookup():
|
|
130
|
+
bl=xwu.block([[1,2,3],"One Two Three".split(), "Un Deux Trois".split()])
|
|
131
|
+
|
|
132
|
+
assert bl.hlookup(1)=="One"
|
|
133
|
+
assert bl.hlookup(3, row2=3)=="Trois"
|
|
134
|
+
with pytest.raises(ValueError):
|
|
135
|
+
bl.hlookup(4)
|
|
136
|
+
with pytest.raises(ValueError):
|
|
137
|
+
bl.hlookup(1, row1=4)
|
|
138
|
+
with pytest.raises(ValueError):
|
|
139
|
+
bl.hlookup(1, row1=3)
|
|
140
|
+
assert bl.lookup_column(1)==1
|
|
141
|
+
assert bl.lookup_column(3)==3
|
|
142
|
+
|
|
105
143
|
|
|
106
144
|
def test_capture(capsys):
|
|
107
145
|
print("abc")
|
|
@@ -372,6 +372,58 @@ class block:
|
|
|
372
372
|
def __repr__(self):
|
|
373
373
|
return f"block({self.value})"
|
|
374
374
|
|
|
375
|
+
def _check_row(self, row, name):
|
|
376
|
+
if row < 1:
|
|
377
|
+
raise ValueError(f"{name}={row} < 1")
|
|
378
|
+
if row > self.number_of_rows:
|
|
379
|
+
raise ValueError(f"{name}={row} > number_of_rows={self.number_of_rows}")
|
|
380
|
+
|
|
381
|
+
def _check_column(self, column, name):
|
|
382
|
+
if column < 1:
|
|
383
|
+
raise ValueError(f"{name}={column} < 1")
|
|
384
|
+
if column > self.number_of_columns:
|
|
385
|
+
raise ValueError(f"{name}={column} > number_of_columns={self.number_of_columns}")
|
|
386
|
+
|
|
387
|
+
def vlookup(self, s, *, row_from=1, row_to=None, column1=1, column2=None):
|
|
388
|
+
if column2 is None:
|
|
389
|
+
column2 = column1 + 1
|
|
390
|
+
self._check_column(column2, "column2")
|
|
391
|
+
row = self.lookup_row(s, row_from=row_from, row_to=row_to, column1=column1)
|
|
392
|
+
return self[row, column2]
|
|
393
|
+
|
|
394
|
+
def lookup_row(self, s, *, row_from=1, row_to=None, column1=1):
|
|
395
|
+
if row_to is None:
|
|
396
|
+
row_to = self.highest_used_row_number
|
|
397
|
+
self._check_row(row_from, "row_from")
|
|
398
|
+
self._check_row(row_to, "row_to")
|
|
399
|
+
self._check_column(column1, "column1")
|
|
400
|
+
|
|
401
|
+
for row in range(row_from, row_to + 1):
|
|
402
|
+
if self[row, column1] == s:
|
|
403
|
+
return row
|
|
404
|
+
raise ValueError(f"{s} not found")
|
|
405
|
+
|
|
406
|
+
def hlookup(self, s, *, column_from=1, column_to=None, row1=1, row2=None):
|
|
407
|
+
if row2 is None:
|
|
408
|
+
row2 = row1 + 1
|
|
409
|
+
self._check_row(row2, "row2")
|
|
410
|
+
column = self.lookup_column(s, column_from=column_from, column_to=column_to, row1=row1)
|
|
411
|
+
return self[row2, column]
|
|
412
|
+
|
|
413
|
+
def lookup_column(self, s, *, column_from=1, column_to=None, row1=1):
|
|
414
|
+
if column_to is None:
|
|
415
|
+
column_to = self.highest_used_column_number
|
|
416
|
+
self._check_column(column_from, "column_from")
|
|
417
|
+
self._check_column(column_to, "column_to")
|
|
418
|
+
self._check_row(row1, "row1")
|
|
419
|
+
|
|
420
|
+
for column in range(column_from, column_to + 1):
|
|
421
|
+
if self[row1, column] == s:
|
|
422
|
+
return column
|
|
423
|
+
raise ValueError(f"{s} not found")
|
|
424
|
+
|
|
425
|
+
def lookup(self, s, *, row_from=1, row_to=None, column1=1, column2=None):
|
|
426
|
+
return self.vlookup(s, row_from=row_from, row_to=row_to, column1=column1, column2=column2)
|
|
375
427
|
|
|
376
428
|
|
|
377
429
|
class _capture:
|
|
@@ -396,7 +448,7 @@ class _capture:
|
|
|
396
448
|
def __init__(self):
|
|
397
449
|
self.stdout = sys.stdout
|
|
398
450
|
self._include_print = False
|
|
399
|
-
self._buffer=[]
|
|
451
|
+
self._buffer = []
|
|
400
452
|
|
|
401
453
|
def __enter__(self):
|
|
402
454
|
sys.stdout = self
|
|
@@ -413,50 +465,47 @@ class _capture:
|
|
|
413
465
|
if self._include_print:
|
|
414
466
|
self.stdout.flush()
|
|
415
467
|
self._buffer.append("\n")
|
|
416
|
-
|
|
417
468
|
|
|
418
469
|
@property
|
|
419
470
|
def value(self):
|
|
420
|
-
result=self.value_keep
|
|
471
|
+
result = self.value_keep
|
|
421
472
|
self.clear()
|
|
422
473
|
return result
|
|
423
|
-
|
|
424
|
-
|
|
474
|
+
|
|
425
475
|
@property
|
|
426
476
|
def value_keep(self):
|
|
427
|
-
result= [[line] for line in self.str_keep.splitlines()]
|
|
477
|
+
result = [[line] for line in self.str_keep.splitlines()]
|
|
428
478
|
return result
|
|
429
|
-
|
|
479
|
+
|
|
430
480
|
@property
|
|
431
481
|
def str(self):
|
|
432
482
|
result = self.str_keep
|
|
433
483
|
self._buffer.clear()
|
|
434
|
-
return result
|
|
435
|
-
|
|
484
|
+
return result
|
|
485
|
+
|
|
436
486
|
@property
|
|
437
487
|
def str_keep(self):
|
|
438
488
|
result = "".join(self._buffer)
|
|
439
|
-
return result
|
|
440
|
-
|
|
489
|
+
return result
|
|
490
|
+
|
|
441
491
|
def clear(self):
|
|
442
492
|
self._buffer.clear()
|
|
443
|
-
|
|
444
|
-
|
|
493
|
+
|
|
445
494
|
@property
|
|
446
495
|
def include_print(self):
|
|
447
496
|
return self._include_print
|
|
448
|
-
|
|
497
|
+
|
|
449
498
|
@include_print.setter
|
|
450
499
|
def include_print(self, value):
|
|
451
|
-
self._include_print=value
|
|
452
|
-
|
|
500
|
+
self._include_print = value
|
|
453
501
|
|
|
454
502
|
|
|
455
503
|
def reset():
|
|
456
|
-
capture.include_print=False
|
|
504
|
+
capture.include_print = False
|
|
457
505
|
capture.clear()
|
|
458
|
-
|
|
459
|
-
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
capture = _capture()
|
|
460
509
|
|
|
461
510
|
|
|
462
511
|
if __name__ == "__main__":
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{xlwings_utils-25.0.0 → xlwings_utils-25.0.0.post0}/xlwings_utils.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|