Skip to content

Commit cde4a09

Browse files
author
Trevor Bye
committed
removed object type inf from _maybe_casted_values
1 parent fa3cf13 commit cde4a09

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

pandas/core/frame.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4496,10 +4496,7 @@ class max type
44964496

44974497
def _maybe_casted_values(index, labels=None):
44984498
values = index._values
4499-
if not isinstance(index, (PeriodIndex, DatetimeIndex)):
4500-
if values.dtype == np.object_:
4501-
values = lib.maybe_convert_objects(values)
4502-
4499+
45034500
# if we have the labels, extract the values with a mask
45044501
if labels is not None:
45054502
mask = labels == -1
Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,40 @@
11
import pytest
2-
import numpy as np
32
import pandas as pd
4-
import pandas._testing as tm
53

64

7-
@pytest.mark.parametrize('test_dtype', [object, 'int8', 'int16', 'int32', 'int64'])
5+
@pytest.mark.parametrize('test_dtype', [object, 'int64'])
86
def test_dtypes(test_dtype):
97
df = pd.DataFrame({'A': pd.Series([1, 2, 3], dtype=test_dtype), 'B': [1, 2, 3]})
108
expected = df.dtypes.values[0].type
119

1210
result = df.set_index('A').index.dtype.type
1311
assert result == expected
12+
13+
14+
@pytest.fixture
15+
def mixed_series():
16+
return pd.Series([1, 2, 3, 'apple', 'corn'], dtype=object)
17+
18+
19+
@pytest.fixture
20+
def int_series():
21+
return pd.Series([100, 200, 300, 400, 500])
22+
23+
24+
def test_dtypes_between_queries(mixed_series, int_series)
25+
df = pd.DataFrame({'item': mixed_series, 'cost': int_series})
26+
27+
orig_dtypes = df.dtypes
28+
item_dtype = orig_dtypes.get('item').type
29+
cost_dtype = orig_dtypes.get('cost').type
30+
expected = {'item': item_dtype, 'cost': cost_dtype}
31+
32+
# after applying a query that would remove strings from the 'item' series with dtype: object,
33+
# that series should remain as dtype: object as it becomes an index, and again as it becomes
34+
# a column again after calling reset_index()
35+
dtypes_transformed = df.query('cost < 400').set_index('item').reset_index().dtypes
36+
item_dtype_transformed = dtypes_transformed.get('item').type
37+
cost_dtype_transformed = dtypes_transformed.get('cost').type
38+
result = {'item': item_dtype_transformed, 'cost': cost_dtype_transformed}
39+
40+
assert result == expected

0 commit comments

Comments
 (0)