Skip to content
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

SEOD-1531. Fix dataframe sort with a pivot with the new pandas v2 API #371

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,19 @@ Changelog is organized by the version of this library, commit date and main poin
- Important feature
-----

2023 September
2023 December

#### [8.0.5] - 2023-12-18
- Fix dataframe sort with a pivot with the new pandas v2 API
- Optimize it by getting rid of `reset_index` and `set_index` method calls when sorting

2023 November

#### [8.0.4] - 2023-11-06
Make removal of date total when generating highcharts more flexible by localizing the datetime when filtering out the totals. This will work with timezone aware datetimes as well not aware ones.

2023 September

#### [8.0.3] - 2023-09-06
- Specify extras dependencies correctly

Expand Down
2 changes: 1 addition & 1 deletion fireant/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ def __hash__(self) -> int:
Term.__hash__ = __hash__


__version__ = "8.0.4"
__version__ = "8.0.5"
16 changes: 8 additions & 8 deletions fireant/widgets/pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,15 @@ def sort_data_frame(self, data_frame: pd.DataFrame):
# If there are no sort arguments or the data frame is a single row, then no need to sort
return data_frame

# reset the index so all columns can be sorted together
index_names = data_frame.index.names
unsorted = data_frame.reset_index()
column_names = list(unsorted.columns)
# Get the list of index names and column names to be able to sort them together
index_names = list(data_frame.index.names)
column_names = list(data_frame.columns)
all_sort_columns = index_names + column_names

ascending = self.ascending if self.ascending is not None else True

sort = wrap_list(self.sort)
sort_columns = [column_names[column] for column in sort if column < len(column_names)]
sort_columns = [all_sort_columns[column] for column in sort if column < len(all_sort_columns)]

if not sort_columns:
return data_frame
Expand All @@ -220,13 +220,13 @@ def sort_data_frame(self, data_frame: pd.DataFrame):
if isinstance(ascending, list) and len(ascending) != len(sort_columns):
ascending = ascending[0] if len(ascending) > 0 else None

sorted = unsorted.sort_values(sort_columns, ascending=ascending).set_index(index_names)
data_frame_sorted = data_frame.sort_values(sort_columns, ascending=ascending)

# Maintain the single metric name
if hasattr(data_frame, "name"):
sorted.name = data_frame.name
data_frame_sorted.name = data_frame.name

return sorted
return data_frame_sorted

def add_formatting(
self, dimensions: List[Field], items: List[Field], pivot_df: pd.DataFrame, use_raw_values: bool
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "fireant"
version = "8.0.4"
version = "8.0.5"
description = ""
authors = ["Ąžuolas Krušna <[email protected]>"]
readme = "README.rst"
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 8.0.4
current_version = 8.0.5
commit = True
tag = True

Expand Down
Loading