forked from dotnet/machinelearning
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Rows collection, similar to Columns * Doc * Some minor clean up * Make DataFrameRow a view into the DataFrame * sq * Address feedback * Remove DataFrame.RowCount * More row count changes * sq * Address feedback * Merge upstream
- Loading branch information
Prashanth Govindarajan
committed
Dec 5, 2019
1 parent
c6eb2f7
commit 7cee9d9
Showing
11 changed files
with
291 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Text; | ||
|
||
namespace Microsoft.Data.Analysis | ||
{ | ||
/// <summary> | ||
/// A DataFrameRow is a collection of values that represent a row in a <see cref="DataFrame"/>. | ||
/// </summary> | ||
public class DataFrameRow : IEnumerable<object> | ||
{ | ||
private readonly DataFrame _dataFrame; | ||
private readonly long _rowIndex; | ||
internal DataFrameRow(DataFrame df, long rowIndex) | ||
{ | ||
Debug.Assert(rowIndex < df.Columns.RowCount); | ||
_dataFrame = df; | ||
_rowIndex = rowIndex; | ||
} | ||
|
||
/// <summary> | ||
/// Returns an enumerator of the values in this row. | ||
/// </summary> | ||
public IEnumerator<object> GetEnumerator() | ||
{ | ||
foreach (DataFrameColumn column in _dataFrame.Columns) | ||
{ | ||
yield return column[_rowIndex]; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// An indexer to return the value at <paramref name="index"/>. | ||
/// </summary> | ||
/// <param name="index">The index of the value to return</param> | ||
/// <returns>The value at this <paramref name="index"/>.</returns> | ||
public object this[int index] | ||
{ | ||
get | ||
{ | ||
return _dataFrame.Columns[index][_rowIndex]; | ||
} | ||
set | ||
{ | ||
_dataFrame.Columns[index][_rowIndex] = value; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// A simple string representation of the values in this row | ||
/// </summary> | ||
public override string ToString() | ||
{ | ||
StringBuilder sb = new StringBuilder(); | ||
foreach (object value in this) | ||
{ | ||
sb.Append(value?.ToString() ?? "null").Append(" "); | ||
} | ||
return sb.ToString(); | ||
} | ||
|
||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
|
||
namespace Microsoft.Data.Analysis | ||
{ | ||
/// <summary> | ||
/// Represents the rows of a <see cref="DataFrame"/> | ||
/// </summary> | ||
public class DataFrameRowCollection : IEnumerable<DataFrameRow> | ||
{ | ||
private readonly DataFrame _dataFrame; | ||
|
||
/// <summary> | ||
/// Initializes a <see cref="DataFrameRowCollection"/>. | ||
/// </summary> | ||
internal DataFrameRowCollection(DataFrame dataFrame) | ||
{ | ||
_dataFrame = dataFrame ?? throw new ArgumentNullException(nameof(dataFrame)); | ||
} | ||
|
||
/// <summary> | ||
/// An indexer to return the <see cref="DataFrameRow"/> at <paramref name="index"/> | ||
/// </summary> | ||
/// <param name="index">The row index</param> | ||
public DataFrameRow this[long index] | ||
{ | ||
get | ||
{ | ||
return new DataFrameRow(_dataFrame, index); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Returns an enumerator of <see cref="DataFrameRow"/> objects | ||
/// </summary> | ||
public IEnumerator<DataFrameRow> GetEnumerator() | ||
{ | ||
for (long i = 0; i < Count; i++) | ||
{ | ||
yield return new DataFrameRow(_dataFrame, i); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// The number of rows in this <see cref="DataFrame"/>. | ||
/// </summary> | ||
public long Count => _dataFrame.Columns.RowCount; | ||
|
||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.