forked from pandas-dev/pandas
-
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.
TST/REF: collect tests by method from tests.internals (pandas-dev#37420)
- Loading branch information
1 parent
3c8c4c9
commit 8985801
Showing
8 changed files
with
327 additions
and
305 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from pandas import DataFrame | ||
import pandas._testing as tm | ||
|
||
|
||
class TestEquals: | ||
def test_dataframe_not_equal(self): | ||
# see GH#28839 | ||
df1 = DataFrame({"a": [1, 2], "b": ["s", "d"]}) | ||
df2 = DataFrame({"a": ["s", "d"], "b": [1, 2]}) | ||
assert df1.equals(df2) is False | ||
|
||
def test_equals_different_blocks(self): | ||
# GH#9330 | ||
df0 = DataFrame({"A": ["x", "y"], "B": [1, 2], "C": ["w", "z"]}) | ||
df1 = df0.reset_index()[["A", "B", "C"]] | ||
# this assert verifies that the above operations have | ||
# induced a block rearrangement | ||
assert df0._mgr.blocks[0].dtype != df1._mgr.blocks[0].dtype | ||
|
||
# do the real tests | ||
tm.assert_frame_equal(df0, df1) | ||
assert df0.equals(df1) | ||
assert df1.equals(df0) |
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,42 @@ | ||
from datetime import datetime | ||
|
||
from pandas import DataFrame | ||
import pandas._testing as tm | ||
|
||
|
||
class TestInferObjects: | ||
def test_infer_objects(self): | ||
# GH#11221 | ||
df = DataFrame( | ||
{ | ||
"a": ["a", 1, 2, 3], | ||
"b": ["b", 2.0, 3.0, 4.1], | ||
"c": [ | ||
"c", | ||
datetime(2016, 1, 1), | ||
datetime(2016, 1, 2), | ||
datetime(2016, 1, 3), | ||
], | ||
"d": [1, 2, 3, "d"], | ||
}, | ||
columns=["a", "b", "c", "d"], | ||
) | ||
df = df.iloc[1:].infer_objects() | ||
|
||
assert df["a"].dtype == "int64" | ||
assert df["b"].dtype == "float64" | ||
assert df["c"].dtype == "M8[ns]" | ||
assert df["d"].dtype == "object" | ||
|
||
expected = DataFrame( | ||
{ | ||
"a": [1, 2, 3], | ||
"b": [2.0, 3.0, 4.1], | ||
"c": [datetime(2016, 1, 1), datetime(2016, 1, 2), datetime(2016, 1, 3)], | ||
"d": [2, 3, "d"], | ||
}, | ||
columns=["a", "b", "c", "d"], | ||
) | ||
# reconstruct frame to verify inference is same | ||
result = df.reset_index(drop=True) | ||
tm.assert_frame_equal(result, expected) |
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,52 @@ | ||
import numpy as np | ||
|
||
from pandas import DataFrame | ||
from pandas.core.arrays import PandasArray | ||
|
||
|
||
class TestToDictOfBlocks: | ||
def test_copy_blocks(self, float_frame): | ||
# GH#9607 | ||
df = DataFrame(float_frame, copy=True) | ||
column = df.columns[0] | ||
|
||
# use the default copy=True, change a column | ||
blocks = df._to_dict_of_blocks(copy=True) | ||
for dtype, _df in blocks.items(): | ||
if column in _df: | ||
_df.loc[:, column] = _df[column] + 1 | ||
|
||
# make sure we did not change the original DataFrame | ||
assert not _df[column].equals(df[column]) | ||
|
||
def test_no_copy_blocks(self, float_frame): | ||
# GH#9607 | ||
df = DataFrame(float_frame, copy=True) | ||
column = df.columns[0] | ||
|
||
# use the copy=False, change a column | ||
blocks = df._to_dict_of_blocks(copy=False) | ||
for dtype, _df in blocks.items(): | ||
if column in _df: | ||
_df.loc[:, column] = _df[column] + 1 | ||
|
||
# make sure we did change the original DataFrame | ||
assert _df[column].equals(df[column]) | ||
|
||
|
||
def test_to_dict_of_blocks_item_cache(): | ||
# Calling to_dict_of_blocks should not poison item_cache | ||
df = DataFrame({"a": [1, 2, 3, 4], "b": ["a", "b", "c", "d"]}) | ||
df["c"] = PandasArray(np.array([1, 2, None, 3], dtype=object)) | ||
mgr = df._mgr | ||
assert len(mgr.blocks) == 3 # i.e. not consolidated | ||
|
||
ser = df["b"] # populations item_cache["b"] | ||
|
||
df._to_dict_of_blocks() | ||
|
||
# Check that the to_dict_of_blocks didnt break link between ser and df | ||
ser.values[0] = "foo" | ||
assert df.loc[0, "b"] == "foo" | ||
|
||
assert df["b"] is ser |
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
Oops, something went wrong.