Skip to content

Commit 854619b

Browse files
committed
Merge remote-tracking branch 'upstream/master' into boolean-array
2 parents 6101015 + cad602e commit 854619b

File tree

3 files changed

+39
-14
lines changed

3 files changed

+39
-14
lines changed

ci/code_checks.sh

+4
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,10 @@ if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then
268268

269269
# Individual files
270270

271+
MSG='Doctests accessor.py' ; echo $MSG
272+
pytest -q --doctest-modules pandas/core/accessor.py
273+
RET=$(($RET + $?)) ; echo $MSG "DONE"
274+
271275
MSG='Doctests base.py' ; echo $MSG
272276
pytest -q --doctest-modules pandas/core/base.py
273277
RET=$(($RET + $?)) ; echo $MSG "DONE"

pandas/core/accessor.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,13 @@ def plot(self):
257257
258258
Back in an interactive IPython session:
259259
260-
>>> ds = pd.DataFrame({{'longitude': np.linspace(0, 10),
261-
... 'latitude': np.linspace(0, 20)}})
262-
>>> ds.geo.center
263-
(5.0, 10.0)
264-
>>> ds.geo.plot()
265-
# plots data on a map
260+
.. code-block:: ipython
261+
262+
In [1]: ds = pd.DataFrame({{"longitude": np.linspace(0, 10),
263+
...: "latitude": np.linspace(0, 20)}})
264+
In [2]: ds.geo.center
265+
Out[2]: (5.0, 10.0)
266+
In [3]: ds.geo.plot() # plots data on a map
266267
"""
267268

268269
def decorator(accessor):

pandas/tests/io/json/test_pandas.py

+28-8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@
1515
from pandas import DataFrame, DatetimeIndex, Series, Timestamp, read_json
1616
import pandas._testing as tm
1717

18+
_seriesd = tm.getSeriesData()
19+
20+
_frame = DataFrame(_seriesd)
21+
22+
_cat_frame = _frame.copy()
23+
cat = ["bah"] * 5 + ["bar"] * 5 + ["baz"] * 5 + ["foo"] * (len(_cat_frame) - 15)
24+
_cat_frame.index = pd.CategoricalIndex(cat, name="E")
25+
_cat_frame["E"] = list(reversed(cat))
26+
_cat_frame["sort"] = np.arange(len(_cat_frame), dtype="int64")
27+
1828

1929
def assert_json_roundtrip_equal(result, expected, orient):
2030
if orient == "records" or orient == "values":
@@ -26,6 +36,12 @@ def assert_json_roundtrip_equal(result, expected, orient):
2636

2737
@pytest.mark.filterwarnings("ignore:the 'numpy' keyword is deprecated:FutureWarning")
2838
class TestPandasContainer:
39+
@pytest.fixture(autouse=True)
40+
def setup(self):
41+
self.categorical = _cat_frame.copy()
42+
43+
yield
44+
2945
def test_frame_double_encoded_labels(self, orient):
3046
df = DataFrame(
3147
[["a", "b"], ["c", "d"]],
@@ -167,21 +183,25 @@ def test_roundtrip_str_axes(self, orient, convert_axes, numpy, dtype):
167183
@pytest.mark.parametrize("convert_axes", [True, False])
168184
@pytest.mark.parametrize("numpy", [True, False])
169185
def test_roundtrip_categorical(self, orient, convert_axes, numpy):
170-
cats = ["a", "b"]
171-
df = pd.DataFrame(
172-
pd.Categorical(cats), index=pd.CategoricalIndex(cats), columns=["cat"]
173-
)
186+
# TODO: create a better frame to test with and improve coverage
187+
if orient in ("index", "columns"):
188+
pytest.xfail(f"Can't have duplicate index values for orient '{orient}')")
174189

175-
data = df.to_json(orient=orient)
176-
if numpy and orient != "split":
190+
data = self.categorical.to_json(orient=orient)
191+
if numpy and orient in ("records", "values"):
177192
pytest.xfail(f"Orient {orient} is broken with numpy=True")
178193

179194
result = pd.read_json(
180195
data, orient=orient, convert_axes=convert_axes, numpy=numpy
181196
)
182197

183-
# Categorical dtypes are not preserved on round trip
184-
expected = pd.DataFrame(cats, index=cats, columns=["cat"])
198+
expected = self.categorical.copy()
199+
expected.index = expected.index.astype(str) # Categorical not preserved
200+
expected.index.name = None # index names aren't preserved in JSON
201+
202+
if not numpy and orient == "index":
203+
expected = expected.sort_index()
204+
185205
assert_json_roundtrip_equal(result, expected, orient)
186206

187207
@pytest.mark.parametrize("convert_axes", [True, False])

0 commit comments

Comments
 (0)