Skip to content

Commit

Permalink
CLN: remove __bytes__
Browse files Browse the repository at this point in the history
  • Loading branch information
topper-123 committed May 18, 2019
1 parent a7d3cc9 commit 2053dfa
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 35 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.25.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ Other API Changes
- Bug in :meth:`DatetimeIndex.snap` which didn't preserving the ``name`` of the input :class:`Index` (:issue:`25575`)
- The ``arg`` argument in :meth:`pandas.core.groupby.DataFrameGroupBy.agg` has been renamed to ``func`` (:issue:`26089`)
- The ``arg`` argument in :meth:`pandas.core.window._Window.aggregate` has been renamed to ``func`` (:issue:`26372`)
- Most Pandas classes had a ``__bytes__`` method, which was used for getting a python2-style bytestring representation of the object. This method has been removed as a part of dropping Python2 (:issue:`26447`)

.. _whatsnew_0250.deprecations:

Expand Down
9 changes: 0 additions & 9 deletions pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,6 @@ def __str__(self):
"""
raise AbstractMethodError(self)

def __bytes__(self):
"""
Return a bytes representation for a particular object.
"""
from pandas._config import get_option

encoding = get_option("display.encoding")
return str(self).encode(encoding, 'replace')

def __repr__(self):
"""
Return a string representation for a particular object.
Expand Down
9 changes: 0 additions & 9 deletions pandas/core/dtypes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,6 @@ def __str__(self):
"""
return self.name

def __bytes__(self):
"""
Return a string representation for a particular object.
"""
from pandas._config import get_option

encoding = get_option("display.encoding")
return str(self).encode(encoding, 'replace')

def __repr__(self):
"""
Return a string representation for a particular object.
Expand Down
9 changes: 6 additions & 3 deletions pandas/tests/frame/test_repr_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,12 @@ def test_unicode_string_with_unicode(self):
df = DataFrame({'A': ["\u05d0"]})
str(df)

def test_bytestring_with_unicode(self):
df = DataFrame({'A': ["\u05d0"]})
bytes(df)
def test_str_to_bytes_raises(self):
# GH 26447
df = DataFrame({'A': ["abc"]})
msg = "^'str' object cannot be interpreted as an integer$"
with pytest.raises(TypeError, match=msg):
bytes(df)

def test_very_wide_info_repr(self):
df = DataFrame(np.random.randn(10, 20),
Expand Down
6 changes: 0 additions & 6 deletions pandas/tests/indexes/multi/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,6 @@ def test_unicode_string_with_unicode():
str(idx)


def test_bytestring_with_unicode():
d = {"a": ["\u05d0", 2, 3], "b": [4, 5, 6], "c": [7, 8, 9]}
idx = pd.DataFrame(d).set_index(["a", "b"]).index
bytes(idx)


def test_repr_max_seq_item_setting(idx):
# GH10182
idx = idx.repeat(50)
Expand Down
10 changes: 6 additions & 4 deletions pandas/tests/indexes/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2388,10 +2388,12 @@ def test_print_unicode_columns(self):
"c": [7, 8, 9]})
repr(df.columns) # should not raise UnicodeDecodeError

@pytest.mark.parametrize("func", [str, bytes])
def test_with_unicode(self, func):
index = Index(list(range(1000)))
func(index)
def test_str_to_bytes_raises(self):
# GH 26447
index = Index([str(x) for x in range(10)])
msg = "^'str' object cannot be interpreted as an integer$"
with pytest.raises(TypeError, match=msg):
bytes(index)

def test_intersect_str_dates(self):
dt_dates = [datetime(2012, 2, 9), datetime(2012, 2, 22)]
Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/indexes/test_frozen.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import warnings

import numpy as np
import pytest

from pandas.core.indexes.frozen import FrozenList, FrozenNDArray
from pandas.tests.test_base import CheckImmutable, CheckStringMixin
Expand Down Expand Up @@ -49,6 +50,12 @@ def test_difference_dupe(self):
expected = FrozenList([1, 3])
self.check_result(result, expected)

def test_tricky_container_to_bytes_raises(self):
# GH 26447
msg = "^'str' object cannot be interpreted as an integer$"
with pytest.raises(TypeError, match=msg):
bytes(self.unicode_container)


class TestFrozenNDArray(CheckImmutable, CheckStringMixin):
mutable_methods = ('put', 'itemset', 'fill')
Expand All @@ -68,6 +75,9 @@ def test_constructor_warns(self):
with tm.assert_produces_warning(FutureWarning):
FrozenNDArray([1, 2, 3])

def test_tricky_container_to_bytes(self):
bytes(self.unicode_container)

def test_shallow_copying(self):
original = self.container.copy()
assert isinstance(self.container.view(), FrozenNDArray)
Expand Down
10 changes: 7 additions & 3 deletions pandas/tests/series/test_repr.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import datetime, timedelta

import numpy as np
import pytest

import pandas as pd
from pandas import (
Expand Down Expand Up @@ -152,9 +153,12 @@ def test_unicode_string_with_unicode(self):
df = Series(["\u05d0"], name="\u05d1")
str(df)

def test_bytestring_with_unicode(self):
df = Series(["\u05d0"], name="\u05d1")
bytes(df)
def test_str_to_bytes_raises(self):
# GH 26447
df = Series(["abc"], name="abc")
msg = "^'str' object cannot be interpreted as an integer$"
with pytest.raises(TypeError, match=msg):
bytes(df)

def test_timeseries_repr_object_dtype(self):
index = Index([datetime(2000, 1, 1) + timedelta(i)
Expand Down
1 change: 0 additions & 1 deletion pandas/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def test_tricky_container(self):
pytest.skip('Need unicode_container to test with this')
repr(self.unicode_container)
str(self.unicode_container)
bytes(self.unicode_container)


class CheckImmutable:
Expand Down

0 comments on commit 2053dfa

Please sign in to comment.