Skip to content

Solved issue #22471 Replaced TestData with fixtures #22928

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
254 changes: 127 additions & 127 deletions pandas/tests/frame/test_analytics.py

Large diffs are not rendered by default.

218 changes: 109 additions & 109 deletions pandas/tests/frame/test_axis_select_reindex.py

Large diffs are not rendered by default.

140 changes: 70 additions & 70 deletions pandas/tests/frame/test_block_internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,110 +32,110 @@
class TestDataFrameBlockInternals(TestData):

def test_cast_internals(self):
casted = DataFrame(self.frame._data, dtype=int)
expected = DataFrame(self.frame._series, dtype=int)
casted = DataFrame(float_frame._data, dtype=int)
expected = DataFrame(float_frame._series, dtype=int)
assert_frame_equal(casted, expected)

casted = DataFrame(self.frame._data, dtype=np.int32)
expected = DataFrame(self.frame._series, dtype=np.int32)
casted = DataFrame(float_frame._data, dtype=np.int32)
expected = DataFrame(float_frame._series, dtype=np.int32)
assert_frame_equal(casted, expected)

def test_consolidate(self):
self.frame['E'] = 7.
consolidated = self.frame._consolidate()
float_frame['E'] = 7.
consolidated = float_frame._consolidate()
assert len(consolidated._data.blocks) == 1

# Ensure copy, do I want this?
recons = consolidated._consolidate()
assert recons is not consolidated
tm.assert_frame_equal(recons, consolidated)

self.frame['F'] = 8.
assert len(self.frame._data.blocks) == 3
float_frame['F'] = 8.
assert len(float_frame._data.blocks) == 3

self.frame._consolidate(inplace=True)
assert len(self.frame._data.blocks) == 1
float_frame._consolidate(inplace=True)
assert len(float_frame._data.blocks) == 1

def test_consolidate_deprecation(self):
self.frame['E'] = 7
float_frame['E'] = 7
with tm.assert_produces_warning(FutureWarning):
self.frame.consolidate()
float_frame.consolidate()

def test_consolidate_inplace(self):
frame = self.frame.copy() # noqa
frame = float_frame.copy() # noqa

# triggers in-place consolidation
for letter in range(ord('A'), ord('Z')):
self.frame[chr(letter)] = chr(letter)
float_frame[chr(letter)] = chr(letter)

def test_values_consolidate(self):
self.frame['E'] = 7.
assert not self.frame._data.is_consolidated()
_ = self.frame.values # noqa
assert self.frame._data.is_consolidated()
float_frame['E'] = 7.
assert not float_frame._data.is_consolidated()
_ = float_frame.values # noqa
assert float_frame._data.is_consolidated()

def test_modify_values(self):
self.frame.values[5] = 5
assert (self.frame.values[5] == 5).all()
float_frame.values[5] = 5
assert (float_frame.values[5] == 5).all()

# unconsolidated
self.frame['E'] = 7.
self.frame.values[6] = 6
assert (self.frame.values[6] == 6).all()
float_frame['E'] = 7.
float_frame.values[6] = 6
assert (float_frame.values[6] == 6).all()

def test_boolean_set_uncons(self):
self.frame['E'] = 7.
float_frame['E'] = 7.

expected = self.frame.values.copy()
expected = float_frame.values.copy()
expected[expected > 1] = 2

self.frame[self.frame > 1] = 2
assert_almost_equal(expected, self.frame.values)
float_frame[float_frame > 1] = 2
assert_almost_equal(expected, float_frame.values)

def test_values_numeric_cols(self):
self.frame['foo'] = 'bar'
float_frame['foo'] = 'bar'

values = self.frame[['A', 'B', 'C', 'D']].values
values = float_frame[['A', 'B', 'C', 'D']].values
assert values.dtype == np.float64

def test_values_lcd(self):

# mixed lcd
values = self.mixed_float[['A', 'B', 'C', 'D']].values
values = mixed_float_frame[['A', 'B', 'C', 'D']].values
assert values.dtype == np.float64

values = self.mixed_float[['A', 'B', 'C']].values
values = mixed_float_frame[['A', 'B', 'C']].values
assert values.dtype == np.float32

values = self.mixed_float[['C']].values
values = mixed_float_frame[['C']].values
assert values.dtype == np.float16

# GH 10364
# B uint64 forces float because there are other signed int types
values = self.mixed_int[['A', 'B', 'C', 'D']].values
values = mixed_int_frame[['A', 'B', 'C', 'D']].values
assert values.dtype == np.float64

values = self.mixed_int[['A', 'D']].values
values = mixed_int_frame[['A', 'D']].values
assert values.dtype == np.int64

# B uint64 forces float because there are other signed int types
values = self.mixed_int[['A', 'B', 'C']].values
values = mixed_int_frame[['A', 'B', 'C']].values
assert values.dtype == np.float64

# as B and C are both unsigned, no forcing to float is needed
values = self.mixed_int[['B', 'C']].values
values = mixed_int_frame[['B', 'C']].values
assert values.dtype == np.uint64

values = self.mixed_int[['A', 'C']].values
values = mixed_int_frame[['A', 'C']].values
assert values.dtype == np.int32

values = self.mixed_int[['C', 'D']].values
values = mixed_int_frame[['C', 'D']].values
assert values.dtype == np.int64

values = self.mixed_int[['A']].values
values = mixed_int_frame[['A']].values
assert values.dtype == np.int32

values = self.mixed_int[['C']].values
values = mixed_int_frame[['C']].values
assert values.dtype == np.uint8

def test_constructor_with_convert(self):
Expand Down Expand Up @@ -219,11 +219,11 @@ def test_construction_with_mixed(self):
expected = Series({'datetime64[ns]': 3})

# mixed-type frames
self.mixed_frame['datetime'] = datetime.now()
self.mixed_frame['timedelta'] = timedelta(days=1, seconds=1)
assert self.mixed_frame['datetime'].dtype == 'M8[ns]'
assert self.mixed_frame['timedelta'].dtype == 'm8[ns]'
result = self.mixed_frame.get_dtype_counts().sort_values()
float_string_frame['datetime'] = datetime.now()
float_string_frame['timedelta'] = timedelta(days=1, seconds=1)
assert float_string_frame['datetime'].dtype == 'M8[ns]'
assert float_string_frame['timedelta'].dtype == 'm8[ns]'
result = float_string_frame.get_dtype_counts().sort_values()
expected = Series({'float64': 4,
'object': 1,
'datetime64[ns]': 1,
Expand Down Expand Up @@ -298,7 +298,7 @@ def test_equals_different_blocks(self):

def test_copy_blocks(self):
# API/ENH 9607
df = DataFrame(self.frame, copy=True)
df = DataFrame(float_frame, copy=True)
column = df.columns[0]

# use the default copy=True, change a column
Expand All @@ -316,7 +316,7 @@ def test_copy_blocks(self):

def test_no_copy_blocks(self):
# API/ENH 9607
df = DataFrame(self.frame, copy=True)
df = DataFrame(float_frame, copy=True)
column = df.columns[0]

# use the copy=False, change a column
Expand All @@ -333,28 +333,28 @@ def test_no_copy_blocks(self):
assert _df[column].equals(df[column])

def test_copy(self):
cop = self.frame.copy()
cop = float_frame.copy()
cop['E'] = cop['A']
assert 'E' not in self.frame
assert 'E' not in float_frame

# copy objects
copy = self.mixed_frame.copy()
assert copy._data is not self.mixed_frame._data
copy = float_string_frame.copy()
assert copy._data is not float_string_frame._data

def test_pickle(self):
unpickled = tm.round_trip_pickle(self.mixed_frame)
assert_frame_equal(self.mixed_frame, unpickled)
unpickled = tm.round_trip_pickle(float_string_frame)
assert_frame_equal(float_string_frame, unpickled)

# buglet
self.mixed_frame._data.ndim
float_string_frame._data.ndim

# empty
unpickled = tm.round_trip_pickle(self.empty)
unpickled = tm.round_trip_pickle(empty_frame)
repr(unpickled)

# tz frame
unpickled = tm.round_trip_pickle(self.tzframe)
assert_frame_equal(self.tzframe, unpickled)
unpickled = tm.round_trip_pickle(timezone_frame)
assert_frame_equal(timezone_frame, unpickled)

def test_consolidate_datetime64(self):
# numpy vstack bug
Expand Down Expand Up @@ -389,8 +389,8 @@ def test_consolidate_datetime64(self):
tm.assert_index_equal(pd.DatetimeIndex(df.ending), ser_ending.index)

def test_is_mixed_type(self):
assert not self.frame._is_mixed_type
assert self.mixed_frame._is_mixed_type
assert not float_frame._is_mixed_type
assert float_string_frame._is_mixed_type

def test_get_numeric_data(self):
# TODO(wesm): unused?
Expand Down Expand Up @@ -450,21 +450,21 @@ def test_get_numeric_data_extension_dtype(self):

def test_convert_objects(self):

oops = self.mixed_frame.T.T
oops = float_string_frame.T.T
converted = oops._convert(datetime=True)
assert_frame_equal(converted, self.mixed_frame)
assert_frame_equal(converted, float_string_frame)
assert converted['A'].dtype == np.float64

# force numeric conversion
self.mixed_frame['H'] = '1.'
self.mixed_frame['I'] = '1'
float_string_frame['H'] = '1.'
float_string_frame['I'] = '1'

# add in some items that will be nan
length = len(self.mixed_frame)
self.mixed_frame['J'] = '1.'
self.mixed_frame['K'] = '1'
self.mixed_frame.loc[0:5, ['J', 'K']] = 'garbled'
converted = self.mixed_frame._convert(datetime=True, numeric=True)
length = len(float_string_frame)
float_string_frame['J'] = '1.'
float_string_frame['K'] = '1'
float_string_frame.loc[0:5, ['J', 'K']] = 'garbled'
converted = float_string_frame._convert(datetime=True, numeric=True)
assert converted['H'].dtype == 'float64'
assert converted['I'].dtype == 'int64'
assert converted['J'].dtype == 'float64'
Expand All @@ -473,14 +473,14 @@ def test_convert_objects(self):
assert len(converted['K'].dropna()) == length - 5

# via astype
converted = self.mixed_frame.copy()
converted = float_string_frame.copy()
converted['H'] = converted['H'].astype('float64')
converted['I'] = converted['I'].astype('int64')
assert converted['H'].dtype == 'float64'
assert converted['I'].dtype == 'int64'

# via astype, but errors
converted = self.mixed_frame.copy()
converted = float_string_frame.copy()
with tm.assert_raises_regex(ValueError, 'invalid literal'):
converted['H'].astype('int32')

Expand Down
24 changes: 12 additions & 12 deletions pandas/tests/frame/test_combine_concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,20 +459,20 @@ def test_combine_first_mixed(self):

def test_combine_first(self):
# disjoint
head, tail = self.frame[:5], self.frame[5:]
head, tail = float_frame[:5], float_frame[5:]

combined = head.combine_first(tail)
reordered_frame = self.frame.reindex(combined.index)
reordered_frame = float_frame.reindex(combined.index)
assert_frame_equal(combined, reordered_frame)
assert tm.equalContents(combined.columns, self.frame.columns)
assert tm.equalContents(combined.columns, float_frame.columns)
assert_series_equal(combined['A'], reordered_frame['A'])

# same index
fcopy = self.frame.copy()
fcopy = float_frame.copy()
fcopy['A'] = 1
del fcopy['C']

fcopy2 = self.frame.copy()
fcopy2 = float_frame.copy()
fcopy2['B'] = 0
del fcopy2['D']

Expand All @@ -496,20 +496,20 @@ def test_combine_first(self):
assert (combined['A'][:10] == 0).all()

# no overlap
f = self.frame[:10]
g = self.frame[10:]
f = float_frame[:10]
g = float_frame[10:]
combined = f.combine_first(g)
assert_series_equal(combined['A'].reindex(f.index), f['A'])
assert_series_equal(combined['A'].reindex(g.index), g['A'])

# corner cases
comb = self.frame.combine_first(self.empty)
assert_frame_equal(comb, self.frame)
comb = float_frame.combine_first(empty_frame)
assert_frame_equal(comb, float_frame)

comb = self.empty.combine_first(self.frame)
assert_frame_equal(comb, self.frame)
comb = empty_frame.combine_first(float_frame)
assert_frame_equal(comb, float_frame)

comb = self.frame.combine_first(DataFrame(index=["faz", "boo"]))
comb = float_frame.combine_first(DataFrame(index=["faz", "boo"]))
assert "faz" in comb.index

# #2525
Expand Down
Loading