5
$\begingroup$

Given

ds = Dataset[{"a b", "c-d"} ]

multi-character StringSplit is broken with Dataset (10.1 regression?)

ds[All, StringSplit[#, {" ", "-"}] &]

enter image description here

though single split charaters works:

ds[All, StringSplit[#, " "] &] // Normal    

{{"a", "b"}, {"c-d"}}

As does plain non-Dataset version of multi-char of course (same output as above)

ds // Normal // Map[StringSplit[#, {" ", "-"}] &]
$\endgroup$
4
  • $\begingroup$ Really 10.2? Or 10.0.2? $\endgroup$ Commented Jun 5, 2015 at 22:53
  • $\begingroup$ My bad, 10.1, edited. $\endgroup$ Commented Jun 5, 2015 at 22:57
  • 2
    $\begingroup$ Same for me with v10.1.0 (OSX) but this will work : ds[All, StringSplit[#, " " | "-"] &] ... $\endgroup$
    – SquareOne
    Commented Jun 5, 2015 at 22:57
  • 1
    $\begingroup$ @SquareOne Confirmed in 10.1.0 under Windows. $\endgroup$
    – Mr.Wizard
    Commented Jun 6, 2015 at 1:43

2 Answers 2

3
$\begingroup$

This issue is due to the same type-inferencing problem described here.

Using printSignatures from the referenced answer, we can see that the type inferencer will only accept a single string as the second argument, not a list:

printSignatures[StringSplit]
  (*
    {Vector[Atom[String], n_]}
    {Atom[String]}
    {Atom[String], Atom[String]}
    {Vector[Atom[String], n_], Atom[String]}
  *)

This list of valid signatures will only accept a single string as the second argument.

The referenced answer shows how to dodge the type-inferencer. We can use similar work-arounds here: either by using Query directly on the raw data...

ds // Normal // Query[Dataset, StringSplit[#, {" ", "-"}] &]

dataset screenshot

... or by disguising the StringSplit operator:

ds[All, StringSplit&[][#, {" ", "-"}] &]

dataset screenshot

Notice how the second work-around loses useful type information in this case, causing the dataset visualization to fall back to a cruder form. We can restore the missing type information by inserting a terminal Dataset ascending operator into the query:

ds[Dataset, StringSplit&[][#, {" ", "-"}] &]

dataset screenshot

This last operation causes the proper type information to be deduced from the final output data (using TypeSystem`DeduceType), restoring the proper visualization.

$\endgroup$
1
  • $\begingroup$ This is fixed in 10.2. P.S. Because StringSplit works on lists of strings, ds[StringSplit[#, " "] &] will work, too. as will just ds[StringSplit] (if you're splitting on whitespace, that is). $\endgroup$ Commented Jul 2, 2015 at 7:31
2
$\begingroup$

It seems to be a problem of your specific version. Im running 10.0.1.0 MacOS and it works just fine.

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.