Skip to content

Commit a7ec260

Browse files
author
Tom Augspurger
committed
added specific test
1 parent 3885851 commit a7ec260

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

doc/source/whatsnew/v1.4.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ Other enhancements
203203
- :meth:`IntegerArray.all` , :meth:`IntegerArray.any`, :meth:`FloatingArray.any`, and :meth:`FloatingArray.all` use Kleene logic (:issue:`41967`)
204204
- Added support for nullable boolean and integer types in :meth:`DataFrame.to_stata`, :class:`~pandas.io.stata.StataWriter`, :class:`~pandas.io.stata.StataWriter117`, and :class:`~pandas.io.stata.StataWriterUTF8` (:issue:`40855`)
205205
- :meth:`DataFrame.__pos__`, :meth:`DataFrame.__neg__` now retain ``ExtensionDtype`` dtypes (:issue:`43883`)
206+
- Added :meth:`api.extension.ExtensionArray._format_array` for extension arrays to control how they are formatted in ``Series`` and ``DataFrame`` (:issue:`26837`)
206207
- The error raised when an optional dependency can't be imported now includes the original exception, for easier investigation (:issue:`43882`)
207208
- Added :meth:`.ExponentialMovingWindow.sum` (:issue:`13297`)
208209
- :meth:`Series.str.split` now supports a ``regex`` argument that explicitly specifies whether the pattern is a regular expression. Default is ``None`` (:issue:`43563`, :issue:`32835`, :issue:`25549`)

pandas/tests/extension/test_format.py

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import pandas as pd
2+
3+
4+
class MyDtype(pd.api.extensions.ExtensionDtype):
5+
name = "mydtype"
6+
type = list
7+
8+
9+
class MyEA(pd.api.extensions.ExtensionArray):
10+
def __init__(self, data):
11+
self.data = data
12+
self._dtype = MyDtype()
13+
14+
@property
15+
def dtype(self):
16+
return self._dtype
17+
18+
def __len__(self):
19+
return 1
20+
21+
def __array__(self, dtype=None):
22+
raise ValueError("Cannot be converted to an array!")
23+
24+
def _format_array(
25+
self,
26+
formatter: None,
27+
float_format: None,
28+
na_rep="NaN",
29+
digits=None,
30+
space=None,
31+
justify="right",
32+
decimal=".",
33+
leading_space=True,
34+
quoting=None,
35+
):
36+
return ["<MyEA>([1])"]
37+
38+
39+
def test_no_conversion():
40+
s = pd.Series(MyEA([1]))
41+
repr(s) # OK!
42+
43+
df = pd.DataFrame({"A": MyEA([1])}, copy=False)
44+
repr(df) # OK!

0 commit comments

Comments
 (0)