8000 ENH: make `Styler` compatible with non-unique indexes by attack68 · Pull Request #41269 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

ENH: make Styler compatible with non-unique indexes #41269

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

Merged
merged 22 commits into from
May 6, 2021
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
1cc569f
ENH: make `Styler.format` compatible with non-unique indexes (with Te…
attack68 May 2, 2021
6982554
ENH: error when using a non-unique subset with .apply and .applymap (…
attack68 May 2, 2021
a3694db
ENH: error when using a non-unique subset with .apply and .applymap: …
attack68 May 2, 2021
5c6669c
ENH: make table_styles work with non-unique + TST: refactor to own file
attack68 May 2, 2021
732c7d5
ENH: error catching
attack68 May 2, 2021
4c99130
ENH: error catching
attack68 May 2, 2021
57e8bef
Merge remote-tracking branch 'upstream/master' into styler_non_unique
attack68 May 3, 2021
a7a2966
ENH: deal with tooltips and raise (inc Tests)
attack68 May 3, 2021
19fb7f9
ENH: deal with tooltips and raise (inc Tests)
attack68 May 3, 2021
4ce559e
ENH: deal with tset_td_classes and raise (inc Tests)
attack68 May 3, 2021
7f28111
ENH: tests for hide_columns
attack68 May 3, 2021
5043c01
ENH: remove style ValueError
attack68 May 3, 2021
9fc6cd3
Merge remote-tracking branch 'upstream/master' into styler_non_unique
attack68 May 4, 2021
09764ba
whats new
attack68 May 4, 2021
9451aae
Merge remote-tracking branch 'upstream/master' into styler_non_unique
attack68 May 5, 2021
4faeb29
prohibit apply and applymap in non-unique case
attack68 May 5, 2021
aed0536
Merge remote-tracking branch 'upstream/master' into styler_non_unique
attack68 May 6, 2021
3a8f11e
move outside loop
attack68 May 6, 2021
51233be
create conditional for performance
attack68 May 6, 2021
8454c5e
create conditional for performance
attack68 May 6, 2021
c3b7af8
take indexing out of loops
attack68 May 6, 2021
20cd19f
take indexing out of loops
attack68 May 6, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
take indexing out of loops
  • Loading branch information
attack68 committed May 6, 2021
commit c3b7af8214cae0681a4bd37062346ac3a29c9b6a
83 changes: 48 additions & 35 deletions pandas/io/formats/style_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,42 +479,55 @@ def format(
subset = non_reducing_slice(subset)
data = self.data.loc[subset]

columns = data.columns
if not isinstance(formatter, dict):
formatter = {col: formatter for col in columns}

if self.index.is_unique and self.columns.is_unique:
for col in columns:
format_func = _maybe_wrap_formatter(
formatter.get(col),
na_rep=na_rep,
precision=precision,
decimal=decimal,
thousands=thousands,
escape=escape,
)

j = self.columns.get_loc(col) # single value
for row, value in data[[col]].itertuples():
i = self.index.get_loc(row) # single value
self._display_funcs[(i, j)] = format_func
else: # will get multiple index value locs to loop over at performance cost
for col in columns:
format_func = _maybe_wrap_formatter(
formatter.get(col),
na_rep=na_rep,
precision=precision,
decimal=decimal,
thousands=thousands,
escape=escape,
)

j_ = self.columns.get_indexer_for([col]) # handle non-unique columns
for row in data[[col]].itertuples():
i_ = self.index.get_indexer_for([row[0]]) # handle non-unique index
for i in i_:
for j in j_:
self._display_funcs[(i, j)] = format_func
formatter = {col: formatter for col in data.columns}

cis = self.columns.get_indexer_for(data.columns)
ris = self.index.get_indexer_for(data.index)
for ci in cis:
format_func = _maybe_wrap_formatter(
formatter.get(self.columns[ci]),
na_rep=na_rep,
precision=precision,
decimal=decimal,
thousands=thousands,
escape=escape,
)
for ri in ris:
self._display_funcs[(ri, ci)] = format_func

# if self.index.is_unique and self.columns.is_unique:
# for col in columns:
# format_func = _maybe_wrap_formatter(
# formatter.get(col),
# na_rep=na_rep,
# precision=precision,
# decimal=decimal,
# thousands=thousands,
# escape=escape,
# )
#
# j = self.columns.get_loc(col) # single value
# for row, value in data[[col]].itertuples():
# i = self.index.get_loc(row) # single value
# self._display_funcs[(i, j)] = format_func
# else: # will get multiple index value locs to loop over at performance cost
# for col in columns:
# format_func = _maybe_wrap_formatter(
# formatter.get(col),
# na_rep=na_rep,
# precision=precision,
# decimal=decimal,
# thousands=thousands,
# escape=escape,
# )
#
# j_ = self.columns.get_indexer_for([col]) # handle non-unique columns
# for row in data[[col]].itertuples():
# i_ = self.index.get_indexer_for([row[0]]) # handle non-unique index
# for i in i_:
# for j in j_:
# self._display_funcs[(i, j)] = format_func

return self

Expand Down
0