So you want to know the number of rows for every example in the batch? You can probably take the max of the unique row IDs in the token type ids created by TapasTokenizer. Small example:
from transformers import TapasTokenizer
import pandas as pd

model_name = 'google/tapas-base-finetuned-wtq'
tokenizer = TapasTokenizer.from_pretrained(model_name)

data = {'Actors': ["Brad Pitt", "Leonardo Di Caprio", "George Clooney"], 'Number of movies': ["87", "53", "69"]}
queries = ["What is the name of the first actor?", "How many movies has George Clooney played in?", "What is the total number of movies?"]
table = pd.DataFrame.from_dict(data)
inputs = tokenizer(table=table, queries=queries, padding='max_length', return_tensors="pt")

row_ids = inputs["token_type_ids"][:,:,2]

You can easily get the unique row IDs for every example in the batch, and then take the max:
import torch

nrows = [torch.max(torch.unique(example)).item() for example in row_ids]

You can pass this variable to the _calculate_expected_result method, such that you can compute the portion result as:
portion_result = count_result / nrows