Skip to content

REGR: change in output formatting for long floats/nan, #11302 #11309

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 1 commit into from
Oct 13, 2015
Merged
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
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.17.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ API changes

- min and max reductions on ``datetime64`` and ``timedelta64`` dtyped series now
result in ``NaT`` and not ``nan`` (:issue:`11245`).

- Regression from 0.16.2 for output formatting of long floats/nan, restored in (:issue:`11302`)
- Prettyprinting sets (e.g. in DataFrame cells) now uses set literal syntax (``{x, y}``) instead of
Legacy Python syntax (``set([x, y])``) (:issue:`11215`)

Expand Down
10 changes: 9 additions & 1 deletion pandas/core/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,15 @@ def _astype(self, dtype, copy=False, raise_on_error=True, values=None,
if values is None:

if issubclass(dtype.type, (compat.text_type, compat.string_types)):
values = self.to_native_types()

# use native type formatting for datetime/tz/timedelta
if self.is_datelike:
values = self.to_native_types()

# astype formatting
else:
values = self.values

else:
values = self.get_values(dtype=dtype)

Expand Down
13 changes: 13 additions & 0 deletions pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -4621,6 +4621,7 @@ def test_astype_str(self):

df = DataFrame({'a' : a, 'b' : b, 'c' : c, 'd' : d, 'e' : e})

# datetimelike
# Test str and unicode on python 2.x and just str on python 3.x
for tt in set([str, compat.text_type]):
result = df.astype(tt)
Expand All @@ -4635,6 +4636,18 @@ def test_astype_str(self):

assert_frame_equal(result, expected)

# float/nan
# 11302
# consistency in astype(str)
for tt in set([str, compat.text_type]):
result = DataFrame([np.NaN]).astype(tt)
expected = DataFrame(['nan'])
assert_frame_equal(result, expected)

result = DataFrame([1.12345678901234567890]).astype(tt)
expected = DataFrame(['1.12345678901'])
assert_frame_equal(result, expected)

def test_array_interface(self):
result = np.sqrt(self.frame)
tm.assertIsInstance(result, type(self.frame))
Expand Down