Feature Type

  • [X] Adding new functionality to pandas

  • [ ] Changing existing functionality in pandas

  • [ ] Removing existing functionality in pandas

Problem Description

When using derived Series type in dataframes, it is useful to be able to skip series type check in assert_frame_equal.

import pandas as pd

class Series(pd.Series):
    @property
    def _constructor( self ):
        return Series

    @property
    def _constructor_expanddim( self ):
        return DataFrame

class DataFrame(pd.DataFrame):
    @property
    def _constructor_sliced( self ):
        return Series

s1 = pd.Series( [0] )
s2 = Series( s1 )

pd.testing.assert_series_equal(s1, s2, check_series_type=False)

df1 = s1.to_frame()
df2 = s2.to_frame()

pd.testing.assert_frame_equal(df1, df2, check_frame_type=False)

In the code above, the first assert passes, but the second fails with the following message:

DataFrame.iloc[:, 0] (column name="0") classes are different
[left]:  Series
[right]: Series

There is currently no easy way to make such dataframes compare equal in testing.

Feature Description

I suggest the following enhancements:

  1. Add a new parameter, check_series_type to assert_frame_equal() that will pass through to assert_series_equal().
  2. Set the new check_series_type to False when check_frame_type is set to False.
  3. When type mismatch is detected but type names are the same, include fully qualified names in the assert message.

Alternative Solutions

Implement enhancements 1 and 3 without 2.

Additional Context

No response

Comment From: alexander-beedie

Makes a lot of sense.

Comment From: lucaslarios

take it

Comment From: lucaslarios

Does this issue still remain relevant?

Comment From: alexander-beedie

Yes. Seems the proposed PR (which works and fixes the issue) was closed as "stale" - but it's actually still valid.

TLDR: assert_frame_equal has the "check_frame_type" param assert_series_equal has the "check_series_type" param

...but...

if you customise frame and series, you can't use assert_frame_equal when testing your class because there is no way to also pass "check_series_type" (and "check_frame_type" doesn't imply it). So it's a simple addition that allows assert_frame_equal to also take "check_series_type", so that this case can be neatly handled by having the same logic flow through cleanly. No changes to existing behaviour.

(If you take a look at the PR it's -literally- a two line change doing exactly that, with 4 lines of docstring; would be really nice if it could be merged ;)

Comment From: jreback

@alexander-beedie and your anyone else could pick up the proposed PR

things are stale if they r just sitting around for too long