-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG/DOC: Styler apply
/format
do not accept callable subset
#46685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks @tehunter for the report. Note that passing the Indexer directly does not work either, even though it is valid input for df.loc
whereas
gives the expected output in the OP. This is because, as the documentation states, So I think the expected output of the code sample in the OP is |
Thanks for the additional perspective, I hadn't considered that the indexer function is returning a 1D array. I guess it is somewhat ambiguous then, as the subset argument itself is a single value, but is it a single key? I think it's reasonable to treat a callable as a special case differently that other single keys. Even
For the final line, the current Styler behavior treats a callable subset as an index value, just like any other single value: If the behavior mirrored It seems like a callable value that feeds into Let me know if you think that's worth pursuing. I could try to put the pull request together when I have some time. |
Thanks @tehunter for the further investigation. Contributions most welcome. I'm not sure the history here, why the subset argument is different from .loc for a 1d indexer, so can't say with certainty how a callable would be treated. @attack68? |
I think the history is that originally there was no Contributions are welcome here to synchronise the usage but be aware:
|
@tehunter on the topic of using callables as an index label to a dataframe, I would consider that a pathological example, which I would expect to be warned against for unpredictable behaviour. I would not design a solution accounting for callables as index labels. |
Pandas version checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
The
.loc
documentation states that a callable function is an allowable input. Styler documentation implies that subset accepts any valid loc input:When a callable is passed to the
subset
argument in styler methods, it raises aKeyError
. The root cause is the_non_reducing_slice
function does not properly handling callable subsets.Expected Behavior
The format function is applied correctly to the "I2" index only.
Installed Versions
INSTALLED VERSIONS
commit : 06d2301
python : 3.10.1.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version :
machine : AMD64
processor :
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United States.1252
pandas : 1.4.1
numpy : 1.22.0
pytz : 2021.3
dateutil : 2.8.2
pip : 22.0.4
setuptools : 60.2.0
Cython : None
pytest : 7.0.1
hypothesis : None
sphinx : 3.5.4
blosc : None
feather : None
xlsxwriter : 3.0.2
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.0.3
IPython : 8.0.0
pandas_datareader: None
bs4 : 4.10.0
bottleneck : 1.3.2
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.5.1
numba : None
numexpr : 2.8.0
odfpy : None
openpyxl : 3.0.9
pandas_gbq : None
pyarrow : None
pyreadstat : 1.1.4
pyxlsb : None
s3fs : None
scipy : 1.7.3
sqlalchemy : 1.4.32
tables : 3.6.1
tabulate : None
xarray : None
xlrd : 2.0.1
xlwt : None
zstandard : None
The text was updated successfully, but these errors were encountered: