question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

nunique + TimeGrouper error

See original GitHub issue

This used to work in the past:

tmp = pd.DataFrame({
        'ID': {pd.Timestamp('2015-06-05 00:00:00'): '0010100903', pd.Timestamp('2015-06-08 00:00:00'): '0010150847'},
        'DATE': {pd.Timestamp('2015-06-05 00:00:00'): '2015-06-05', pd.Timestamp('2015-06-08 00:00:00'): '2015-06-08'}})
tmp.groupby(pd.TimeGrouper('D')).ID.nunique()

but now I get the obscure:

Traceback (most recent call last):
  File "test.py", line 6, in <module>
    tmp.groupby(pd.TimeGrouper('D')).ID.nunique()
  File "/usr/lib/python3/dist-packages/pandas/core/groupby.py", line 2697, in nunique
    name=self.name)
  File "/usr/lib/python3/dist-packages/pandas/core/series.py", line 227, in __init__
    data = SingleBlockManager(data, index, fastpath=True)
  File "/usr/lib/python3/dist-packages/pandas/core/internals.py", line 3736, in __init__
    ndim=1, fastpath=True)
  File "/usr/lib/python3/dist-packages/pandas/core/internals.py", line 2454, in make_block
    placement=placement)
  File "/usr/lib/python3/dist-packages/pandas/core/internals.py", line 87, in __init__
    len(self.values), len(self.mgr_locs)))
ValueError: Wrong number of items passed 2, placement implies 4

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
wavexxcommented, Feb 16, 2016

The logically equivalent:

tmp.groupby(pd.TimeGrouper('D')).ID.apply(lambda x: x.nunique())

works as intended.

0reactions
jrebackcommented, Feb 16, 2016

yeah there were some fixes related to this, but this one didn’t take.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Whats wrong with my grouping or looping? - Stack Overflow
My problem is that sometimes, even tho the conditions are met, it wrongly classifies my data. For instance group "table 5": id nnDist1...
Read more >
GroupBy — pandas 0.25.0 documentation
GroupBy.sem (self[, ddof]), Compute standard error of the mean of groups, ... DataFrameGroupBy.nunique (self[, dropna]), Return DataFrame with number of ...
Read more >
pandas - | notebook.community
A gallery of the most interesting jupyter notebooks online.
Read more >
Source code for pandas.core.groupby
[docs] def sem(self, ddof=1): """ Compute standard error of the mean of groups, ... **kwargs): """ Provide resampling when using a TimeGrouper Return...
Read more >
https://www.psych.mcgill.ca/labs/mogillab/anaconda...
_cython_agg_general(f) b = TimeGrouper(Minute(5), closed='right', label='right') g ... index=np.random.choice(dr, n)) left = ts.resample('30T').nunique() ix ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found