Skip to content

Commit ad89e0d

Browse files
Runnable examples for removing methods of DataFrame.
1 parent 142f2d9 commit ad89e0d

1 file changed

Lines changed: 45 additions & 13 deletions

File tree

src/DataFrame/DataFrame.class.st

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,6 +1726,10 @@ DataFrame >> removeColumn: columnName [
17261726
DataFrame >> removeColumnAt: columnNumber [
17271727
"Removes the column at column index columnNumber from a data frame"
17281728

1729+
"(#(#(1 2) #(3 4)) asDataFrame removeColumnAt: 2) >>> (#(#(1) #(3)) asDataFrame)"
1730+
1731+
"(#(#(r1c1 r1c2) #(r2c1 r2c2)) asDataFrame removeColumnAt: 2) >>> (#(#(r1c1) #(r2c1)) asDataFrame)"
1732+
17291733
(columnNumber < 1 or: [ columnNumber > self numberOfColumns ])
17301734
ifTrue: [ SubscriptOutOfBounds signalFor: columnNumber ].
17311735

@@ -1748,9 +1752,13 @@ DataFrame >> removeColumns: aCollectionOfColumnNames [
17481752
DataFrame >> removeColumnsAt: aCollectionOfColumnIndices [
17491753
"Removes all columns from a data frame whose column indices are present in the collection aCollectionOfColumnIndices"
17501754

1755+
"(#(#(1 2 3) #(4 5 6)) asDataFrame removeColumnsAt: #(2 3)) >>> (#(#(1) #(4)) asDataFrame)"
1756+
1757+
"(#(#(r1c1 r1c2) #(r2c1 r2c2)) asDataFrame removeColumnsAt: #(1 2)) >>> (#(#() #()) asDataFrame)"
1758+
17511759
| columnNamesToRemove |
17521760
columnNamesToRemove := aCollectionOfColumnIndices collect: [ :i |
1753-
columnNames at: i ].
1761+
columnNames at: i ].
17541762
self removeColumns: columnNamesToRemove
17551763
]
17561764

@@ -1767,16 +1775,20 @@ DataFrame >> removeColumnsOfRowElementsSatisfing: aBlock onRowNamed: rowName [
17671775
DataFrame >> removeColumnsOfRowElementsSatisfying: aBlock onRow: rowNumber [
17681776
"Removes columns from a data frame whose row elements at the row index rowNumber satisfy a given block"
17691777

1778+
"(#(#(1 2 3) #(4 5 6)) asDataFrame removeColumnsOfRowElementsSatisfying: [ :x | x > 4 ] onRow: 2) >>> (#(#(1) #(4)) asDataFrame)"
1779+
17701780
| columnNamesCopy |
1771-
(rowNumber < 1 or: [ rowNumber > self numberOfRows ])
1772-
ifTrue: [ SubscriptOutOfBounds signalFor: rowNumber ].
1781+
(rowNumber < 1 or: [ rowNumber > self numberOfRows ]) ifTrue: [
1782+
SubscriptOutOfBounds signalFor: rowNumber ].
17731783

17741784
columnNamesCopy := columnNames deepCopy.
17751785
columnNames removeAll.
17761786
columnNamesCopy withIndexDo: [ :columnName :j |
1777-
(aBlock value: (contents at: rowNumber at: j))
1778-
ifFalse: [ columnNames add: columnName ]].
1779-
contents removeColumnsOfRowElementsSatisfying: aBlock onRow: rowNumber.
1787+
(aBlock value: (contents at: rowNumber at: j)) ifFalse: [
1788+
columnNames add: columnName ] ].
1789+
contents
1790+
removeColumnsOfRowElementsSatisfying: aBlock
1791+
onRow: rowNumber.
17801792

17811793
self numberOfColumns = 0 ifTrue: [ rowNames removeAll ]
17821794
]
@@ -1805,6 +1817,10 @@ DataFrame >> removeColumnsWithNilsAtRowNamed: rowName [
18051817
DataFrame >> removeDuplicatedRows [
18061818
"Removes duplicate rows of a dataframe except the first unique row"
18071819

1820+
"(#(#(1 2) #(3 4) #(1 2)) asDataFrame removeDuplicatedRows) >>> (#(#(1 2) #(3 4)) asDataFrame)"
1821+
1822+
"(#(#(r1c1) #(r2c1) #(r2c1) #(r2c1)) asDataFrame removeDuplicatedRows) >>> (#(#(r1c1) #(r2c1)) asDataFrame)"
1823+
18081824
| numberOfRows nextRowIndex currentRow row aSet |
18091825
aSet := Set new.
18101826
numberOfRows := self numberOfRows.
@@ -1830,8 +1846,12 @@ DataFrame >> removeRow: rowName [
18301846
DataFrame >> removeRowAt: rowNumber [
18311847
"Removes the row at row index rowNumber from a data frame"
18321848

1833-
(rowNumber < 1 or: [ rowNumber > self numberOfRows ])
1834-
ifTrue: [ SubscriptOutOfBounds signalFor: rowNumber ].
1849+
"(#(#(1 2) #(3 4)) asDataFrame removeRowAt: 2) >>> (#(#(1 2)) asDataFrame)"
1850+
1851+
"(#(#(r1c1 r1c2) #(r2c1 r2c2)) asDataFrame removeRowAt: 2) >>> (#(#(r1c1 r1c2)) asDataFrame)"
1852+
1853+
(rowNumber < 1 or: [ rowNumber > self numberOfRows ]) ifTrue: [
1854+
SubscriptOutOfBounds signalFor: rowNumber ].
18351855

18361856
contents removeRowAt: rowNumber.
18371857
rowNames := rowNames copyWithoutIndex: rowNumber
@@ -1849,9 +1869,13 @@ DataFrame >> removeRows: aCollectionOfRowNames [
18491869
DataFrame >> removeRowsAt: aCollectionOfRowIndices [
18501870
"Removes all rows from a data frame whose row indices are present in the collection aCollectionOfRowIndices"
18511871

1872+
"(#(#(1 2) #(3 4) #(5 6)) asDataFrame removeRowsAt: #(2 3)) >>> (#(#(1 2)) asDataFrame)"
1873+
1874+
"(#(#(r1c1 r1c2) #(r2c1 r2c2)) asDataFrame removeRowsAt: #(2)) >>> (#(#(r1c1 r1c2)) asDataFrame)"
1875+
18521876
| rowNamesToRemove |
18531877
rowNamesToRemove := aCollectionOfRowIndices collect: [ :i |
1854-
rowNames at: i ].
1878+
rowNames at: i ].
18551879
self removeRows: rowNamesToRemove
18561880
]
18571881

@@ -1868,24 +1892,32 @@ DataFrame >> removeRowsOfColumnElementsSatisfing: aBlock onColumnNamed: columnNa
18681892
DataFrame >> removeRowsOfColumnElementsSatisfying: aBlock onColumn: columnNumber [
18691893
"Removes rows from a data frame whose column elements at the column index columnNumber satisfy a given block"
18701894

1895+
"(#(#(1 2) #(3 4) #(5 6)) asDataFrame removeRowsOfColumnElementsSatisfying: [ :x | x >= 4 ] onColumn: 2) >>> (#(#(1 2)) asDataFrame)"
1896+
18711897
| rowNamesCopy |
18721898
(columnNumber < 1 or: [ columnNumber > self numberOfColumns ])
18731899
ifTrue: [ SubscriptOutOfBounds signalFor: columnNumber ].
18741900

18751901
rowNamesCopy := rowNames deepCopy.
18761902
rowNames removeAll.
18771903
rowNamesCopy withIndexDo: [ :rowName :i |
1878-
(aBlock value: (contents at: i at: columnNumber))
1879-
ifFalse: [ rowNames add: rowName ] ].
1880-
contents removeRowsOfColumnElementsSatisfying: aBlock onColumn: columnNumber.
1904+
(aBlock value: (contents at: i at: columnNumber)) ifFalse: [
1905+
rowNames add: rowName ] ].
1906+
contents
1907+
removeRowsOfColumnElementsSatisfying: aBlock
1908+
onColumn: columnNumber.
18811909

18821910
self numberOfRows = 0 ifTrue: [ columnNames removeAll ]
18831911
]
18841912

18851913
{ #category : #removing }
18861914
DataFrame >> removeRowsWithNils [
18871915
"Removes all rows from a data frame which have atleast one nil value"
1888-
1916+
1917+
"(#(#(1 2) #(nil 4) #(5 nil)) asDataFrame removeRowsWithNils) >>> (#(#(1 2)) asDataFrame)"
1918+
1919+
"(#(#(r1c1 r1c2) #(nil r2c2)) asDataFrame removeRowsWithNils) >>> (#(#(r1c1 r1c2)) asDataFrame)"
1920+
18891921
1 to: self numberOfColumns do: [ :i |
18901922
self
18911923
removeRowsOfColumnElementsSatisfying: [ :ele | ele isNil ]

0 commit comments

Comments
 (0)