Skip to content

Skip empty cells when unfolding ranges - #35

Open
garak95 wants to merge 1 commit into
klaudyu:mainfrom
garak95:skip-empty-cells
Open

Skip empty cells when unfolding ranges#35
garak95 wants to merge 1 commit into
klaudyu:mainfrom
garak95:skip-empty-cells

Conversation

@garak95

@garak95 garak95 commented Mar 17, 2026

Copy link
Copy Markdown

This PR removes empty cells from ranges when expanding them. This allows mainly statistical functions to work as expected. Cells that do contain a 0 are preserved, of course. Matrices are also unaffected by this change because they would change shape.

I have not found any formula that would suffer from my changes, but maybe I lack imagination? If such case exist, it can be fixed by manually typing 0 in the empty cells, or by adding a setting to control my new behavior.

image

I've considered a few other options to achieve the behavior I was looking for:

  • Introduce a new range syntax to filter empty cells instead, eg a1::a7 or FILTER(a1:a7) but ultimately modifying the regular syntax doesn't seem to have any downsides.
  • Leave the empty cells as zero most of the time, as currently, but filter them for statistical functions. This is difficult because ranges are expanded long before function evaluation. It's certainly possible, however.
  • Remove the entire nullAsZero thing, and leave empty cells be null. Then patch/overload mathjs so that it can decide itself when to convert null to 0 and when to skip null. This is probably the most "correct" way but it's also complicated and seemed overkill.

Other notes:

  • The sum wrapper was already mostly unnecessary since you added null as zero, but with this PR the wrapper is now entirely redundant and could be removed. I did not do it now because I wanted to keep this PR as small as possible.
  • It would be interesting to also ignore cells that contain random text, like spreadsheets do. But at this time it's difficult to know for sure what is or isn't valid at unfolding time. A regex to allow all number formats + units might be "good enough", however. The main benefit would be to be able to put placeholders instead of having empty cells, eg "?" or "N/A" or "Unknown".
  • If a range is entirely empty cells, =median(a1:b7) will return an error. This is how it works in spreadsheets too. But if, you prefer, I can create a 3 lines wrapper to enhance some functions and allow them to return 0 when they receive an empty range (sum/median/mean/min/max might make sense).

This allows statistical functions to work properly.
@WolfgangGolder

Copy link
Copy Markdown

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants