-
Notifications
You must be signed in to change notification settings - Fork 168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Auto: error on underspecified reduce #1833
Open
tophtucker
wants to merge
7
commits into
main
Choose a base branch
from
toph/auto-reduce-error
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
adf7aa8
auto: error on underspecified reduce
tophtucker 3c456ae
fix test, allow null reduce
tophtucker ae5e673
mike doin his thing improvin my stuff
tophtucker 36fd69d
dont throw error for primitive data; add unit test
tophtucker 706ae54
address review comments
tophtucker 0536a25
Merge branch 'main' into toph/auto-reduce-error
tophtucker b3dcb91
Merge branch 'main' into toph/auto-reduce-error
Fil File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -243,3 +243,42 @@ it("Plot.autoSpec makes a faceted heatmap", () => { | |
colorMode: "fill" | ||
}); | ||
}); | ||
|
||
it.only("autoSpec rejects an underspecified reducer", () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ☝️ it.only |
||
// primitive array ok | ||
assert.deepStrictEqual(Plot.autoSpec([74, 65], {x: Plot.identity, y: "max"}), { | ||
fx: null, | ||
fy: null, | ||
x: {value: Plot.identity, reduce: null, zero: false}, | ||
y: {value: null, reduce: "max", zero: false}, | ||
color: {value: null, reduce: null}, | ||
size: {value: null, reduce: null}, | ||
mark: "rule", | ||
markImpl: "ruleX", | ||
markOptions: { | ||
fx: undefined, | ||
fy: undefined, | ||
x: {value: Object.assign([74, 65], {label: undefined})}, | ||
y: undefined, | ||
stroke: undefined, | ||
z: undefined, | ||
r: undefined, | ||
tip: true | ||
}, | ||
transformImpl: "binX", | ||
transformOptions: {stroke: undefined, r: undefined, y: "max"}, | ||
colorMode: "stroke" | ||
}); | ||
// in this case, reducer "max" has no input | ||
assert.throws( | ||
() => | ||
Plot.autoSpec( | ||
[ | ||
{name: "Toph", height: 74}, | ||
{name: "Claire", height: 65} | ||
], | ||
{x: "height", y: "max"} | ||
), | ||
/^Error: setting y reducer to "max" requires setting y field$/ | ||
); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple nits here.
First, isEvery requires values to be an iterable, but mark data can also be an “arrayish” value that is supported by Array.from such as {length: 10}. So, we’d need to handle that case, too. I recommend protecting the call as
isIterable(data) && !isPrimitive(data)
(since any data is not iterable by definition can only contain undefined, as in a sparse array, which we would not consider to be primitive).Second, we should also treat bigints as primitive. (There’s also the symbol type to consider. I guess you could use the mode reducer on non-primitive values? But that’s obscure enough that I wouldn’t worry about it. If you’re doing these things you probably can debug the error.)
Last, I would avoid array.includes(type) in the inner loop. Unless the JavaScript engine is smart, it’ll have to allocate that array afresh for each value, and the call to array.includes is also probably slower than an inline logical expression. It’s better to just write this by hand; see isOrdinal for an example.