dotnet / dotnet/machinelearning

[DataFrame] DataFrame operations "obj" return type

Open
#5,707 7 comments 2 reactions 0 assignees View on GitHub
area-DataFrame
Dominant language
C#
Stars
9.4k
Forks
2k
Avg merge
2d 20h
Merged PRs (30d)
11

Description

Given a DataFrameColumn with data similar to the following:

![image](https://user-images.githubusercontent.com/46974588/73109506-4c745200-3ed1-11ea-9efd-6e7db8013ac8.png)

Performing operations like `Sum` return values of type `obj`. This causes issues when trying to use it in other contexts / operations.

Example:

Suppose I want to manually calculate the sum of a numeric column and divide it by 3:

```fsharp
df.["PetalLength"].Sum() / 3
```

The code throws the following exception - **The type 'int' does not match the type 'obj'**

The first thought is to cast.

```fsharp
((float32)df.["PetalLength"].Sum())
```

This approache, throws exception - **typecheck error The type 'obj' does not support a conversion to the type 'float32**.

The two ways that actually work are the following:

Using the casting operator:

```fsharp
(df.["PetalLength"].Sum() :?> float32) / 3.f
```

or unboxing:

```fsharp
df.["PetalLength"].Sum() |> unbox
```

In a sense it's not really a bug, but the ability to provide the return type and avoid casting would make it cleaner / simpler on the user.

i.e. `df.[PetalLength].Sum()`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.