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 bounded= to remove them from the previews as well as to show just the subset of data we’re working with.

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

ABCDEFGH
4£ million
5Time periodPublic new housingPrivate new housingTotal new housingInfrastructure new workPublic other new workPrivate industrial new workPrivate commercial new work
6Dataset identifier codeMV3WMV3XMVL9MV3YMV3ZMV42MV43
7199721581758819690140156010872125517
8199817481776419448136276334888527655
9199915151598017436132477129916730963
10200019011785319693124306753818231200

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

ABCDEFGH
4£ million
5Time periodPublic new housingPrivate new housingTotal new housingInfrastructure new workPublic other new workPrivate industrial new workPrivate commercial new work
6Dataset identifier codeMV3WMV3XMVL9MV3YMV3ZMV42MV43
7199721581758819690140156010872125517
8199817481776419448136276334888527655
9199915151598017436132477129916730963
10200019011785319693124306753818231200

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

ABCDEFGH
4£ million
5Time periodPublic new housingPrivate new housingTotal new housingInfrastructure new workPublic other new workPrivate industrial new workPrivate commercial new work
6Dataset identifier codeMV3WMV3XMVL9MV3YMV3ZMV42MV43
7199721581758819690140156010872125517
8199817481776419448136276334888527655
9199915151598017436132477129916730963
10200019011785319693124306753818231200