forked from pandas-dev/pandas
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
REF: repr - allow block to override values that get formatted (pandas…
- Loading branch information
1 parent
9b07ef4
commit 929c66f
Showing
7 changed files
with
48 additions
and
2 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
Empty file.
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,29 @@ | ||
# -*- coding: utf-8 -*- | ||
# pylint: disable=W0102 | ||
|
||
import numpy as np | ||
|
||
import pandas as pd | ||
from pandas.core.internals import Block, BlockManager, SingleBlockManager | ||
|
||
|
||
class CustomBlock(Block): | ||
|
||
def formatting_values(self): | ||
return np.array(["Val: {}".format(i) for i in self.values]) | ||
|
||
|
||
def test_custom_repr(): | ||
values = np.arange(3, dtype='int64') | ||
|
||
# series | ||
block = CustomBlock(values, placement=slice(0, 3)) | ||
|
||
s = pd.Series(SingleBlockManager(block, pd.RangeIndex(3))) | ||
assert repr(s) == '0 Val: 0\n1 Val: 1\n2 Val: 2\ndtype: int64' | ||
|
||
# dataframe | ||
block = CustomBlock(values.reshape(1, -1), placement=slice(0, 1)) | ||
blk_mgr = BlockManager([block], [['col'], range(3)]) | ||
df = pd.DataFrame(blk_mgr) | ||
assert repr(df) == ' col\n0 Val: 0\n1 Val: 1\n2 Val: 2' |
File renamed without changes.
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