Skip to content

Commit 732f1f8

Browse files
committed
add DataFrame tests
1 parent decb776 commit 732f1f8

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

pandas/tests/frame/test_dtypes.py

+20
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,26 @@ def test_arg_for_errors_in_astype(self):
677677
df.astype(np.int8, errors='ignore')
678678

679679

680+
@pytest.mark.parametrize('input_vals', [
681+
([1, 2]),
682+
([1.0, 2.0, np.nan]),
683+
(['1', '2']),
684+
(list(pd.date_range('1/1/2011', periods=2, freq='H'))),
685+
(list(pd.date_range('1/1/2011', periods=2, freq='H',
686+
tz='US/Eastern'))),
687+
([pd.Interval(left=0, right=5)]),
688+
])
689+
def test_constructor_list_str(self, input_vals):
690+
# GH 16605
691+
# Ensure that data elements are converted to strings when
692+
# dtype is str, 'str', or 'U'
693+
694+
for dtype in ['str', str, 'U']:
695+
result = DataFrame({'A': input_vals}, dtype=dtype)
696+
expected = DataFrame({'A': input_vals}).astype({'A': dtype})
697+
assert_frame_equal(result, expected)
698+
699+
680700
class TestDataFrameDatetimeWithTZ(TestData):
681701

682702
def test_interleave(self):

pandas/tests/series/test_constructors.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from pandas._libs.tslib import iNaT
2424

2525
from pandas.compat import lrange, range, zip, long
26-
from pandas.util.testing import assert_series_equal
26+
from pandas.util.testing import assert_series_equal, assert_frame_equal
2727
import pandas.util.testing as tm
2828

2929
from .common import TestData
@@ -146,14 +146,15 @@ def test_constructor_list_like(self):
146146
([1, 2]),
147147
([1.0, 2.0, np.nan]),
148148
(['1', '2']),
149-
(pd.date_range('1/1/2011', periods=2)),
150-
(pd.date_range('1/1/2011', periods=2, tz='US/Eastern')),
151-
(pd.Interval(left=0, right=5)),
149+
(list(pd.date_range('1/1/2011', periods=2, freq='H'))),
150+
(list(pd.date_range('1/1/2011', periods=2, freq='H',
151+
tz='US/Eastern'))),
152+
([pd.Interval(left=0, right=5)]),
152153
])
153154
def test_constructor_list_str(self, input_vals):
154155
# GH 16605
155-
# Ensure that data elements are converted to strings when
156-
# dtype is str, 'str', or 'U'
156+
# Ensure that data elements from a list are converted to strings
157+
# when dtype is str, 'str', or 'U'
157158

158159
for dtype in ['str', str, 'U']:
159160
result = Series(input_vals, dtype=dtype)

0 commit comments

Comments
 (0)