-
Notifications
You must be signed in to change notification settings - Fork 7k
[DataFrame] Implements df.as_matrix #2001
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -994,10 +994,31 @@ def test_as_blocks(): | |
|
|
||
|
|
||
| def test_as_matrix(): | ||
| ray_df = create_test_dataframe() | ||
| test_data = TestData() | ||
| frame = rdf.DataFrame(test_data.frame) | ||
| mat = frame.as_matrix() | ||
|
|
||
| frame_columns = frame.columns | ||
| for i, row in enumerate(mat): | ||
| for j, value in enumerate(row): | ||
| col = frame_columns[j] | ||
| if np.isnan(value): | ||
| assert np.isnan(frame[col][i]) | ||
| else: | ||
| assert value == frame[col][i] | ||
|
|
||
| with pytest.raises(NotImplementedError): | ||
| ray_df.as_matrix() | ||
| # mixed type | ||
| mat = rdf.DataFrame(test_data.mixed_frame).as_matrix(['foo', 'A']) | ||
| assert mat[0, 0] == 'bar' | ||
|
|
||
| df = rdf.DataFrame({'real': [1, 2, 3], 'complex': [1j, 2j, 3j]}) | ||
| mat = df.as_matrix() | ||
| assert mat[0, 0] == 1j | ||
|
|
||
| # single block corner case | ||
| mat = rdf.DataFrame(test_data.frame).as_matrix(['A', 'B']) | ||
| expected = test_data.frame.reindex(columns=['A', 'B']).values | ||
| tm.assert_almost_equal(mat, expected) | ||
|
||
|
|
||
|
|
||
| def test_asfreq(): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use the fixture model for testing here and define the numpy matrix in the tests to compare against?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this need a fixture model?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixture models are more in tune with what we have been using. The simplest way to do this test would be to run
to_matrixor__array__on bothpd_dfandray_dfand check equality.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will make a pass over the tests to unify them in a later PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good.