Selection: Multiple Selection Warnings#
Now we’re doing more dynamic seletions it’s time to talk about multiple selection warnings.
When extracting tabulated data in this manner, the likelyhood is that we only want to use each value once - as such where a single cell appears in two selections within a single preview a warning will be raised.
This default behaviour can be toggled off as needed.
Source Data#
The data source we’re using for these examples is shown below:
Note - this particular table has some very verbose headers we don’t care about, so we’ll be using |
---|
The full data source can be downloaded here. We’ll be using th 6th tab named “Table2a”.
from tidychef import acquire, preview
from tidychef.selection import XlsxSelectable
table: XlsxSelectable = acquire.xlsx.http("https://github.com/mikeAdamss/tidychef/raw/main/tests/fixtures/xlsx/ons-oic.xlsx", tables="Table 2a")
preview(table, bounded="A4:H10")
Table 2a
A | B | C | D | E | F | G | H | |
4 | £ million | |||||||
5 | Time period | Public new housing | Private new housing | Total new housing | Infrastructure new work | Public other new work | Private industrial new work | Private commercial new work |
6 | Dataset identifier code | MV3W | MV3X | MVL9 | MV3Y | MV3Z | MV42 | MV43 |
7 | 1997 | 2158 | 17588 | 19690 | 14015 | 6010 | 8721 | 25517 |
8 | 1998 | 1748 | 17764 | 19448 | 13627 | 6334 | 8885 | 27655 |
9 | 1999 | 1515 | 15980 | 17436 | 13247 | 7129 | 9167 | 30963 |
10 | 2000 | 1901 | 17853 | 19693 | 12430 | 6753 | 8182 | 31200 |
Example Multiple Selection Warning#
The following is a simple example of a multiple selection warning.
from tidychef import acquire, preview
from tidychef.selection import XlsxSelectable
table: XlsxSelectable = acquire.xlsx.http("https://github.com/mikeAdamss/tidychef/raw/main/tests/fixtures/xlsx/ons-oic.xlsx", tables="Table 2a")
# Select the whole of row 6
row = table.excel_ref('6')
# Select the whole of column E
column = table.excel_ref('E')
# Lets' preview and see what happens
preview(row, column, bounded="A4:H10")
Cell Appears in Multiple Selections |
Unnamed Selection: 0 |
Unnamed Selection: 1 |
Table 2a
A | B | C | D | E | F | G | H | |
4 | £ million | |||||||
5 | Time period | Public new housing | Private new housing | Total new housing | Infrastructure new work | Public other new work | Private industrial new work | Private commercial new work |
6 | Dataset identifier code | MV3W | MV3X | MVL9 | MV3Y | MV3Z | MV42 | MV43 |
7 | 1997 | 2158 | 17588 | 19690 | 14015 | 6010 | 8721 | 25517 |
8 | 1998 | 1748 | 17764 | 19448 | 13627 | 6334 | 8885 | 27655 |
9 | 1999 | 1515 | 15980 | 17436 | 13247 | 7129 | 9167 | 30963 |
10 | 2000 | 1901 | 17853 | 19693 | 12430 | 6753 | 8182 | 31200 |
Turning Off Multiple Selection Warnings#
To turn off multiple selection warnings you just pass multiple_selection_warning=False
to the preview function.
You’ll notice the cell in question just gets coloured by the last selection containing it that is passed to preview()
instead.
from typing import List
from tidychef import acquire, preview
from tidychef.selection import XlsxSelectable
tables: List[XlsxSelectable] = acquire.xlsx.http("https://github.com/mikeAdamss/tidychef/raw/main/tests/fixtures/xlsx/ons-oic.xlsx")
table = tables[5]
# Select the whole of row 6
row = table.excel_ref('6')
# Select the whole of column E
column = table.excel_ref('E')
# Lets' preview and see what happens
preview(row, column, bounded="A4:H10", multiple_selection_warning=False)
Unnamed Selection: 0 |
Unnamed Selection: 1 |
Table 2a
A | B | C | D | E | F | G | H | |
4 | £ million | |||||||
5 | Time period | Public new housing | Private new housing | Total new housing | Infrastructure new work | Public other new work | Private industrial new work | Private commercial new work |
6 | Dataset identifier code | MV3W | MV3X | MVL9 | MV3Y | MV3Z | MV42 | MV43 |
7 | 1997 | 2158 | 17588 | 19690 | 14015 | 6010 | 8721 | 25517 |
8 | 1998 | 1748 | 17764 | 19448 | 13627 | 6334 | 8885 | 27655 |
9 | 1999 | 1515 | 15980 | 17436 | 13247 | 7129 | 9167 | 30963 |
10 | 2000 | 1901 | 17853 | 19693 | 12430 | 6753 | 8182 | 31200 |