Skip to content

Commit

Permalink
Fixed facet_grid with column named "key"
Browse files Browse the repository at this point in the history
fixes #734
  • Loading branch information
has2k1 committed Jan 4, 2024
1 parent c4dc225 commit de98e6b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
2 changes: 2 additions & 0 deletions doc/changelog.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ title: Changelog
- Fixed bug where `theme(legend_background=element_blank())`{.py} messed up
the position of the legend, instead of only removing the background.

- Fixed using `facet_grid` with a column named `key`. ({{< issue 734 >}})

### Enhancements

- All `__all__` variables are explicitly assigned to help static typecheckers
Expand Down
12 changes: 2 additions & 10 deletions plotnine/_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -988,23 +988,15 @@ def resolution(x, zero=True):

def cross_join(df1: pd.DataFrame, df2: pd.DataFrame) -> pd.DataFrame:
"""
Return a dataframe that is a cross between dataframes
df1 and df2
ref: https://github.com/pydata/pandas/issues/5401
Return a cross between df1 & df2 if each is not empty
"""
if len(df1) == 0:
return df2

if len(df2) == 0:
return df1

# Add as lists so that the new index keeps the items in
# the order that they are added together
all_columns = list(pd.Index(list(df1.columns) + list(df2.columns)))
df1["key"] = 1
df2["key"] = 1
return df1.merge(df2, on="key").loc[:, all_columns]
return df1.join(df2, how="cross") # type: ignore


def to_inches(value: float, units: str) -> float:
Expand Down

0 comments on commit de98e6b

Please sign in to comment.