You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The methods of DataFrame were created at different time over 2 years. Because of that API is sometimes inconsistent. We need to review all methods, remove the redundant ones and rename those with confusing names. Protocols also have to be reviewed.
Collections in Smalltalk respond to a message do: which accepts aBlock as argument and applies that block to every element of the collection. aBlock therefore takes one argument - the element on which it will be applied.
Example:
Transcript open; clear.
#(a b c d)do: [ :each |
Transcriptshow: each; cr ].
Result:
a
b
c
d
For sequenceable collections, there is also a message withIndexDo: which allows to enumerate their elements together with their indices. This message accepts a two-argument block: first argument is the element, second argument is the index of that element.
Example:
Transcript open; clear.
#(a b c d)withIndexDo: [ :each:index |
Transcriptshow:'[', index asString, '] ', each; cr ].
Result:
[1] a
[2] b
[3] c
[4] d
OrderedDictionary, which is the superclass of DataSeries is basically a SequentiableCollection (an array) with keys instead of indices. In my opinion, current implementation of OrderedDictionary is bad and very inconsistent - we should improve it. So I will show examples on DataSeries.
DataSeries has message do: which takes aBlock as an argument and applies it to every element of the series. The block therefore takes one argument - the element to which it should be applied:
There is also a message withIndexDo: which allows you to enumerate elements together with their indices. It takes as argument a two-argument block which expects an element and an index:
Example:
Transcript open; clear.
temperature withIndexDo: [ :each:index |
Transcriptshow:'[', index asString, '] ', each asString; cr ].
Result:
[1] 2.4
[2] 0.5
[3] -1.2
[4] -2.3
[5] 3.2
And a similar message withKeyDo: that allows you to enumerate elements together with their keys:
Example:
Transcript open; clear.
temperature withKeyDo: [ :each:key |
Transcriptshow:'[', key asString, '] ', each asString; cr ].
Activity
AtharvaKhare commentedon May 13, 2019
DataSeries withKeyDo: aBlockneedsaBlockto have:valueand:keyas arguments. It should, however, accept only 1 argument - key.Also, since DataSeries inherits OrderedDictionary, which has
keysDo(andkeysAndValuesDo), do we needwithKeyDo?olekscode commentedon May 15, 2019
I'm not sure if I understood you correctly, but:
Collections in Smalltalk respond to a message
do:which acceptsaBlockas argument and applies that block to every element of the collection.aBlocktherefore takes one argument - the element on which it will be applied.Example:
Result:
For sequenceable collections, there is also a message
withIndexDo:which allows to enumerate their elements together with their indices. This message accepts a two-argument block: first argument is the element, second argument is the index of that element.Example:
Result:
OrderedDictionary, which is the superclass ofDataSeriesis basically aSequentiableCollection(an array) with keys instead of indices. In my opinion, current implementation ofOrderedDictionaryis bad and very inconsistent - we should improve it. So I will show examples onDataSeries.DataSerieshas messagedo:which takesaBlockas an argument and applies it to every element of the series. The block therefore takes one argument - the element to which it should be applied:Example:
Result:
There is also a message
withIndexDo:which allows you to enumerate elements together with their indices. It takes as argument a two-argument block which expects an element and an index:Example:
Result:
And a similar message
withKeyDo:that allows you to enumerate elements together with their keys:Example:
Result:
And there is a message
keysDo:which allows you to enumerate only keys. It takes a one-argument block and applies it to each key of the data series.Example:
Result:
In fact, it is the same as asking
temperatureseries for a collection of itskeysand sendingdo:message to that collection:Interesting literature on this topic:
2.7. Enumerating values of data seriesof the DataFrame bookletEnumerating Elements(p. 136) of Chapter9. Protocol for All Collection Classesof the Blue BookwithIndexDo:AtharvaKhare commentedon May 15, 2019
Thanks for the detailed explanation and links. I assumed
withKeysDo:was same askeysDoand got confused. Now it's all clear :)