8000 DEPR: DataFrame.get_dtype_counts by mroeschke · Pull Request #27145 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

DEPR: DataFrame.get_dtype_counts #27145

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

Merged
merged 27 commits into from
Jul 3, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
convert tests
  • Loading branch information
Matt Roeschke committed Jul 1, 2019
commit 0df4dd946402d21308a4b9f248a0a235c60676cc
25 changes: 15 additions & 10 deletions pandas/tests/frame/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,23 +836,28 @@ def test_timedeltas(self):
df = DataFrame(dict(A=Series(date_range('2012-1-1', periods=3,
freq='D')),
B=Series([timedelta(days=i) for i in range(3)])))
result = Series(df._data.get_dtype_counts()).sort_index()
expected = Series(
{'datetime64[ns]': 1, 'timedelta64[ns]': 1}).sort_index()
result = df.dtypes
expected = Series([np.dtype('datetime64[ns]'),
np.dtype('timedelta64[ns]')],
index=list("AB"))
assert_series_equal(result, expected)

df['C'] = df['A'] + df['B']
expected = Series(
{'datetime64[ns]': 2, 'timedelta64[ns]': 1}).sort_values()
result = Series(df._data.get_dtype_counts()).sort_values()
result = df.dtypes
expected = Series([np.dtype('datetime64[ns]'),
np.dtype('timedelta64[ns]'),
np.dtype('datetime64[ns]')],
index=list("ABC"))
assert_series_equal(result, expected)

# mixed int types
df['D'] = 1
expected = Series({'datetime64[ns]': 2,
'timedelta64[ns]': 1,
'int64': 1}).sort_values()
result = Series(df._data.get_dtype_counts()).sort_values()
result = df.dtypes
expected = Series([np.dtype('datetime64[ns]'),
np.dtype('timedelta64[ns]'),
np.dtype('datetime64[ns]'),
np.dtype('int64')],
index=list("ABCD"))
assert_series_equal(result, expected)

def test_arg_for_errors_in_astype(self):
Expand Down
35 changes: 25 additions & 10 deletions pandas/tests/frame/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,15 +300,23 @@ def test_getitem_boolean_casting(self, datetime_frame):
df['F1'] = df['F'].copy()

casted = df[df > 0]
result = Series(casted._data.get_dtype_counts())
expected = Series({'float64': 4, 'int32': 2, 'int64': 2})
result = casted.dtypes
expected = Series([np.dtype('float64')] * 4 +
[np.dtype('int32')] * 2 +
[np.dtype('int64')] * 2,
index=['A', 'B', 'C', 'D', 'E', 'E1', 'F', 'F1'])
assert_series_equal(result, expected)

# int block splitting
df.loc[df.index[1:3], ['E1', 'F1']] = 0
casted = df[df > 0]
result = Series(casted._data.get_dtype_counts())
expected = Series({'float64': 6, 'int32': 1, 'int64': 1})
result = casted.dtypes
expected = Series([np.dtype('float64')] * 4 +
[np.dtype('int32')] +
[np.dtype('float64')] +
[np.dtype('int64')] +
[np.dtype('float64')],
index=['A', 'B', 'C', 'D', 'E', 'E1', 'F', 'F1'])
assert_series_equal(result, expected)

# where dtype conversions
Expand Down Expand Up @@ -615,8 +623,9 @@ def test_setitem_cast(self, float_frame):
df = DataFrame(np.random.rand(30, 3), columns=tuple('ABC'))
df['event'] = np.nan
df.loc[10, 'event'] = 'foo'
result = Series(df._data.get_dtype_counts()).sort_values()
expected = Series({'float64': 3, 'object': 1}).sort_values()
result = df.dtypes
expected = Series([np.dtype('float64')] * 3 + [np.dtype('object')],
index=['A', 'B', 'C', 'event'])
assert_series_equal(result, expected)

# Test that data type is preserved . #5782
Expand Down Expand Up @@ -1614,8 +1623,10 @@ def test_setitem_single_column_mixed_datetime(self):
df['timestamp'] = Timestamp('20010102')

# check our dtypes
result = Series(df._data.get_dtype_counts())
expected = Series({'float64': 3, 'datetime64[ns]': 1})
result = df.dtypes
expected = Series([np.dtype('float64')] * 3 +
[np.dtype('datetime64[ns]')],
index=['foo', 'bar', 'baz', 'timestamp'])
assert_series_equal(result, expected)

# set an allowable datetime64 type
Expand Down Expand Up @@ -2637,13 +2648,17 @@ def _check_get(df, cond, check_dtypes=True):
for c in ['float32', 'float64',
'int32', 'int64']})
df.iloc[1, :] = 0
result = Series(df.where(df >= 0)._data.get_dtype_counts())
result = df.dtypes
expected = Series([np.dtype('float32'),
np.dtype('float64'),
np.dtype('int32'),
np.dtype('int64')],
index=['float32', 'float64', 'int32', 'int64'])

# when we don't preserve boolean casts
#
# expected = Series({ 'float32' : 1, 'float64' : 3 })

expected = Series({'float32': 1, 'float64': 1, 'int32': 1, 'int64': 1})
assert_series_equal(result, expected)

# aligning
Expand Down
0