Skip to content

Commit edd24b8

Browse files
authored
Merge pull request #204 from Joshua-Dias-Barreto/unique-values
Method uniqueValues of class DataSeries now doesn't sort values
2 parents 0fe28db + 6d660a3 commit edd24b8

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

src/DataFrame/Array.extension.st

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,10 @@ Array >> leastCommonSuperclassOf: firstClass and: secondClass [
3939

4040
^ Object
4141
]
42+
43+
{ #category : #'*DataFrame' }
44+
Array >> sortIfPossible [
45+
"Sort if possible"
46+
47+
^ [ self sort ] on: Error do: [ self ].
48+
]

src/DataFrame/DataSeries.class.st

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -237,15 +237,15 @@ DataSeries >> crossTabulateWith: aSeries [
237237
ifFalse: [ SizeMismatch signal ].
238238

239239
df := DataFrame withRows:
240-
(self uniqueValues collect: [ :each1 |
241-
aSeries uniqueValues collect: [ :each2 |
240+
(self uniqueValues sortIfPossible collect: [ :each1 |
241+
aSeries uniqueValues sortIfPossible collect: [ :each2 |
242242
(1 to: self size) inject: 0 into: [ :accum :i |
243243
(((self atIndex: i) = each1) and: ((aSeries atIndex: i) = each2))
244244
ifTrue: [ accum + 1 ]
245245
ifFalse: [ accum ] ] ] ]).
246246

247-
df rowNames: self uniqueValues.
248-
df columnNames: aSeries uniqueValues.
247+
df rowNames: self uniqueValues sortIfPossible.
248+
df columnNames: aSeries uniqueValues sortIfPossible.
249249
^ df
250250
]
251251

@@ -342,7 +342,7 @@ DataSeries >> groupBy: otherSeries aggregateUsing: aBlock as: aNewName [
342342
| groupMap |
343343
self size = otherSeries size ifFalse: [ SizeMismatch signal ].
344344

345-
groupMap := (otherSeries uniqueValues collect: [ :e | e -> OrderedCollection new ]) asOrderedDictionary.
345+
groupMap := (otherSeries uniqueValues sortIfPossible collect: [ :e | e -> OrderedCollection new ]) asOrderedDictionary.
346346

347347
1 to: self size do: [ :index | (groupMap at: (otherSeries atIndex: index)) add: (self atIndex: index) ].
348348

@@ -383,7 +383,7 @@ DataSeries >> groupByUniqueValuesAndAggregateUsing: aBlock as: aNewName [
383383
"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"
384384

385385
| groupMap |
386-
groupMap := (self uniqueValues collect: [ :e | e -> OrderedCollection new ]) asOrderedDictionary.
386+
groupMap := (self uniqueValues sortIfPossible collect: [ :e | e -> OrderedCollection new ]) asOrderedDictionary.
387387

388388
self do: [ :each | (groupMap at: each) add: each ].
389389

@@ -741,11 +741,7 @@ DataSeries >> thirdQuartile [
741741

742742
{ #category : #accessing }
743743
DataSeries >> uniqueValues [
744-
| v |
745-
v := self asSet asArray.
746-
747-
"Sort if possible"
748-
^ [ v sort ] on: Error do: [ v ]
744+
^ self asSet asArray
749745
]
750746

751747
{ #category : #statistics }

0 commit comments

Comments
 (0)