@@ -253,22 +253,21 @@ DataSeries >> countNonNils [
253253{ #category : #statistics }
254254DataSeries >> crossTabulateWith: aSeries [
255255 " A DataFrame is returned which is useful in quantitatively analyzing the relationship of values in one data series with the values in another data series"
256-
257- | df |
258256
259- ( self size = aSeries size)
260- ifFalse: [ SizeMismatch signal ].
257+ | df |
258+ self size = aSeries size ifFalse: [ SizeMismatch signal ].
261259
262260 df := DataFrame withRows:
263- (self uniqueValues sortIfPossible collect: [ :each1 |
264- aSeries uniqueValues sortIfPossible collect: [ :each2 |
265- (1 to: self size) inject: 0 into: [ :accum :i |
266- (((self atIndex: i) = each1) and : ((aSeries atIndex: i) = each2))
267- ifTrue: [ accum + 1 ]
268- ifFalse: [ accum ] ] ] ]).
269-
270- df rowNames: self uniqueValues sortIfPossible.
271- df columnNames: aSeries uniqueValues sortIfPossible.
261+ (self removeDuplicates sortIfPossible collect: [ :each1 |
262+ aSeries removeDuplicates sortIfPossible collect: [ :each2 |
263+ (1 to: self size) inject: 0 into: [ :accum :i |
264+ ((self atIndex: i) = each1 and :
265+ (aSeries atIndex: i) = each2)
266+ ifTrue: [ accum + 1 ]
267+ ifFalse: [ accum ] ] ] ]).
268+
269+ df rowNames: self removeDuplicates sortIfPossible.
270+ df columnNames: aSeries removeDuplicates sortIfPossible.
272271 ^ df
273272]
274273
@@ -365,11 +364,17 @@ DataSeries >> groupBy: otherSeries aggregateUsing: aBlock as: aNewName [
365364 | groupMap |
366365 self size = otherSeries size ifFalse: [ SizeMismatch signal ].
367366
368- groupMap := (otherSeries uniqueValues sortIfPossible collect: [ :e | e - > OrderedCollection new ]) asOrderedDictionary.
367+ groupMap := (otherSeries removeDuplicates sortIfPossible collect: [
368+ :e | e - > OrderedCollection new ]) asOrderedDictionary.
369369
370- 1 to: self size do: [ :index | (groupMap at: (otherSeries atIndex: index)) add: (self atIndex: index) ].
370+ 1 to: self size do: [ :index |
371+ (groupMap at: (otherSeries atIndex: index)) add:
372+ (self atIndex: index) ].
371373
372- ^ self class withKeys: groupMap keys values: (groupMap values collect: aBlock) name: aNewName
374+ ^ self class
375+ withKeys: groupMap keys
376+ values: (groupMap values collect: aBlock)
377+ name: aNewName
373378]
374379
375380{ #category : #grouping }
@@ -406,11 +411,15 @@ DataSeries >> groupByUniqueValuesAndAggregateUsing: aBlock as: aNewName [
406411 " Group my values by unique values, aggregate them using aBlock, and answer a new DataSeries with theunique values as keys, aggregated values of myself as values, and aNewName as name"
407412
408413 | groupMap |
409- groupMap := (self uniqueValues sortIfPossible collect: [ :e | e - > OrderedCollection new ]) asOrderedDictionary.
414+ groupMap := (self removeDuplicates sortIfPossible collect: [ :e |
415+ e - > OrderedCollection new ]) asOrderedDictionary.
410416
411417 self do: [ :each | (groupMap at: each) add: each ].
412418
413- ^ self class withKeys: groupMap keys values: (groupMap values collect: aBlock) name: aNewName
419+ ^ self class
420+ withKeys: groupMap keys
421+ values: (groupMap values collect: aBlock)
422+ name: aNewName
414423]
415424
416425{ #category : #testing }
@@ -466,8 +475,10 @@ DataSeries >> isCategorical [
466475{ #category : #' categorical-numerical' }
467476DataSeries >> isNumerical [
468477 " Returns true if all values of the data series are numerical values and returns false otherwise"
469-
470- ^ forcedIsNumerical ifNil: [ (self uniqueValues copyWithout: nil ) allSatisfy: [ :each | each isNumber ] ]
478+
479+ ^ forcedIsNumerical ifNil: [
480+ (self removeDuplicates copyWithout: nil ) allSatisfy: [ :each |
481+ each isNumber ] ]
471482]
472483
473484{ #category : #testing }
@@ -583,6 +594,13 @@ DataSeries >> removeAtIndex: aNumber [
583594 ^ self removeAt: (self keys at: aNumber)
584595]
585596
597+ { #category : #removing }
598+ DataSeries >> removeDuplicates [
599+ " Answer the unique values of the receiver by removing duplicates"
600+
601+ ^ self asSet asArray
602+ ]
603+
586604{ #category : #removing }
587605DataSeries >> removeNils [
588606 " Removes elements with nil values from the data series"
@@ -801,9 +819,13 @@ DataSeries >> thirdQuartile [
801819
802820{ #category : #accessing }
803821DataSeries >> uniqueValues [
804- " Answer the unique values of the receiver"
805-
806- ^ self asSet asArray
822+
823+ self
824+ deprecated:
825+ ' The name of this method has been changed to removeDuplicates.'
826+ transformWith:
827+ ' `@receiver uniqueValues' - > ' `@receiver removeDuplicates' .
828+ ^ self removeDuplicates
807829]
808830
809831{ #category : #statistics }
0 commit comments