Skip to content

REF: extract classes in pandas/core/describe.py #39186

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 7 commits into from
Jan 19, 2021

Conversation

ivanovmg
Copy link
Member

Extract classes SeriesDescriber and DataFrameDescriber.
In the next steps I am going to enable strategy pattern and move corresponding describe functions to the concrete strategy classes (for each datatype).

@ivanovmg ivanovmg changed the title Refactor/describe REF: extract classes in pandas/core/describe.py Jan 15, 2021
@ivanovmg ivanovmg requested a review from jreback January 15, 2021 13:01

def create_describer(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would just inline this to above

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


def __init__(
self,
series: "Series",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you make this a common method in NDFrame (and changes series -> data) to match dataframe

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will check that. But I guess it is going to violate Liskov principle.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like nothing is violated. It seems to work.

frame : DataFrame
DataFrame to be described.
include : 'all', list-like of dtypes or None (default), optional
data : DataFrame
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

match series for data / datetime_is_numeric and add other args

self,
frame: "DataFrame",
*,
include: Optional[Union[str, Sequence[str]]],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can do super() for first 2 args

@jreback jreback added the Refactor Internal refactoring of code label Jan 15, 2021
@@ -376,3 +380,8 @@ def refine_percentiles(percentiles: Optional[Sequence[float]]) -> Sequence[float
raise ValueError("percentiles cannot contain duplicates")

return unique_pcts


def validate_frame(frame: "DataFrame"):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a reason not to do this in the constructor? e.g. L148

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I though of simplifying the constructor.
Ideally I would create a method _initialize_frame, which will perform the validation under the hood and return the frame.

self.frame = self._initialize_frame(frame)

But that will be a static method, which you prefer not to use.

If you consider that this extraction is unnecessary, then I can definitely inline it into the constructor.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved into the constructor.

@ivanovmg ivanovmg requested a review from jreback January 18, 2021 04:25
@jreback jreback added this to the 1.3 milestone Jan 19, 2021
@jreback jreback merged commit 77e488b into pandas-dev:master Jan 19, 2021
@jreback
Copy link
Contributor

jreback commented Jan 19, 2021

thanks @ivanovmg

@ivanovmg ivanovmg deleted the refactor/describe branch January 20, 2021 03:31
nofarm3 pushed a commit to nofarm3/pandas that referenced this pull request Jan 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Refactor Internal refactoring of code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants