-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
ENH: Add downcast as method to DataFrame and Series #51641
Changes from all commits
b7ba887
bcad0a6
a8404bd
f6d7ef0
bacc5a1
c44949d
b9850b7
e67bd06
19ccd66
49fca8d
1e79841
60c61aa
b006219
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import numpy as np | ||
|
||
from pandas import DataFrame | ||
import pandas._testing as tm | ||
from pandas.tests.copy_view.util import get_array | ||
|
||
|
||
class TestDowncast: | ||
def test_downcast(self, using_copy_on_write): | ||
df = DataFrame({"a": [1.0, 2.0], "b": 1.5}) | ||
df_orig = df.copy() | ||
result = df.downcast() | ||
|
||
assert not np.shares_memory(get_array(df, "a"), get_array(result, "a")) | ||
if using_copy_on_write: | ||
assert np.shares_memory(get_array(df, "b"), get_array(result, "b")) | ||
else: | ||
assert not np.shares_memory(get_array(df, "b"), get_array(result, "b")) | ||
|
||
result.iloc[0, 1] = 100.5 | ||
tm.assert_frame_equal(df, df_orig) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from pandas import DataFrame | ||
import pandas._testing as tm | ||
|
||
|
||
class TestDowncast: | ||
def test_downcast(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. parametrize over frame_or_series? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this makes it more complicated There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the alternative is to implement an analogous test in the series tests There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just do
? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a series test already, should have commented. Are you ok with that? |
||
df = DataFrame({"a": [1.0, 2.0], "b": 1.5, "c": 2.0, "d": "a"}) | ||
result = df.downcast() | ||
expected = DataFrame({"a": [1, 2], "b": 1.5, "c": 2, "d": "a"}) | ||
tm.assert_frame_equal(result, expected) |
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.
i would have expected this to be handled within the Manager method. am i wrong to be surprised?
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.
Doesn’t really matter, when we supported dict like inputs this was better, but can move it to the manager now