Skip to content

ENH: followup for resample, #11841  #12140

Closed
@jreback

Description

@jreback

@jorisvandenbossche comments for followup on #11841

  • the repr: can we follow here PEP8 as well? :-) (I mean spaces after the comma's, I think this would make it a bit more readable, maybe also quotes around the strings)
  • upsample has been removed? (but is still in the documentation) Or is this now asfreq?

doc are updated, it IS now .asfreq

  • apply gives Exception: Must produce aggregated value (for a series) if you pass it a function that does not return a aggregated value. For groupby this works, would be nice to have this consistent.
    When applying it on a resampled dataframe, you get the cryptic ValueError: cannot copy sequence with size 3 to array axis with dimension 180 message. Typical example is just a .apply(lambda x: x)
  • Resampler.fillna has no explanation
  • DatetimeIndexResampler has no docstring yet
  • apply, agg, aggregate have no docstring, transform a very brief
    In theory it would be best if this were addressed in this PR, but given the PEP8 changes waiting on this PR, it's OK for me to leave this for a follow-up PR
  • Further, an inconsistency between r.agg() and r[].agg() in:
In [81]: df = pd.DataFrame(np.random.randn(1000, 3),
   ....:                  index=pd.date_range('1/1/2012', freq='S', periods=1000
),
   ....:                  columns=['A', 'B', 'C'])

In [82]: r = df.resample('3T')

In [83]: r.agg({'r1':'mean', 'r2':'sum'})
SpecificationError: nested dictionary is ambiguous in aggregation

In [84]: r[['A', 'B']].agg({'r1':'mean', 'r2':'sum'})
Out[84]:
                           r1                   r2
                            A         B          A          B
2012-01-01 00:00:00 -0.059093  0.040993 -10.636800   7.378766
2012-01-01 00:03:00 -0.037877  0.055133  -6.817820   9.923978
2012-01-01 00:06:00 -0.101921  0.061913 -18.345769  11.144373
2012-01-01 00:09:00  0.097927 -0.074492  17.626838 -13.408612
2012-01-01 00:12:00 -0.027901  0.035319  -5.022220   6.357459
2012-01-01 00:15:00 -0.037696  0.022259  -3.769580   2.225884
  • validate that we have tests for all combinations of aggregation
grouped.agg({'C': 'mean', 'D': 'sum'})
grouped[['C', 'D']].agg({'C': 'mean', 'D': 'sum'})
grouped.agg({'C': ['mean', 'sum'], 'D': ['mean', 'sum']})
grouped.agg({'C': {'r': 'mean', 'r2': 'sum'}, 'D': {'r': 'mean', 'r2': 'sum'}})

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions