-
-
Notifications
You must be signed in to change notification settings - Fork 18k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BUG: Misc fixes for SparseSeries indexing with MI
closes #13144 Author: sinhrks <sinhrks@gmail.com> Closes #13163 from sinhrks/sparse_multi and squashes the following commits: eb24102 [sinhrks] BUG: Misc fixes for SparseSeries indexing with MI
- Loading branch information
Showing
7 changed files
with
214 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import print_function | ||
|
||
import numpy as np | ||
import pandas as pd | ||
|
||
import pandas.util.testing as tm | ||
from pandas.compat import (is_platform_windows, | ||
is_platform_32bit) | ||
from pandas.core.config import option_context | ||
|
||
|
||
use_32bit_repr = is_platform_windows() or is_platform_32bit() | ||
|
||
|
||
class TestSeriesFormatting(tm.TestCase): | ||
|
||
_multiprocess_can_split_ = True | ||
|
||
def test_sparse_max_row(self): | ||
s = pd.Series([1, np.nan, np.nan, 3, np.nan]).to_sparse() | ||
result = repr(s) | ||
dtype = '' if use_32bit_repr else ', dtype=int32' | ||
exp = ("0 1.0\n1 NaN\n2 NaN\n3 3.0\n" | ||
"4 NaN\ndtype: float64\nBlockIndex\n" | ||
"Block locations: array([0, 3]{0})\n" | ||
"Block lengths: array([1, 1]{0})".format(dtype)) | ||
self.assertEqual(result, exp) | ||
|
||
with option_context("display.max_rows", 3): | ||
# GH 10560 | ||
result = repr(s) | ||
exp = ("0 1.0\n ... \n4 NaN\n" | ||
"dtype: float64\nBlockIndex\n" | ||
"Block locations: array([0, 3]{0})\n" | ||
"Block lengths: array([1, 1]{0})".format(dtype)) | ||
self.assertEqual(result, exp) | ||
|
||
def test_sparse_mi_max_row(self): | ||
idx = pd.MultiIndex.from_tuples([('A', 0), ('A', 1), ('B', 0), | ||
('C', 0), ('C', 1), ('C', 2)]) | ||
s = pd.Series([1, np.nan, np.nan, 3, np.nan, np.nan], | ||
index=idx).to_sparse() | ||
result = repr(s) | ||
dtype = '' if use_32bit_repr else ', dtype=int32' | ||
exp = ("A 0 1.0\n 1 NaN\nB 0 NaN\n" | ||
"C 0 3.0\n 1 NaN\n 2 NaN\n" | ||
"dtype: float64\nBlockIndex\n" | ||
"Block locations: array([0, 3], dtype=int32)\n" | ||
"Block lengths: array([1, 1]{0})".format(dtype)) | ||
self.assertEqual(result, exp) | ||
|
||
with option_context("display.max_rows", 3): | ||
# GH 13144 | ||
result = repr(s) | ||
exp = ("A 0 1.0\n ... \nC 2 NaN\n" | ||
"dtype: float64\nBlockIndex\n" | ||
"Block locations: array([0, 3], dtype=int32)\n" | ||
"Block lengths: array([1, 1]{0})".format(dtype)) | ||
self.assertEqual(result, exp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters