Skip to content

global name 'iNaT' is not defined #9675

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

Closed
samzhang111 opened this issue Mar 18, 2015 · 3 comments
Closed

global name 'iNaT' is not defined #9675

samzhang111 opened this issue Mar 18, 2015 · 3 comments
Labels
Milestone

Comments

@samzhang111
Copy link

Trying to perform this operation on a groupby object called clusters:

clusters.agg({'diffs': lambda x: x.quantile(.5)})

where diffs is a column of Timedelta objects.

Getting the error:

/usr/local/lib/python2.7/dist-packages/pandas/core/groupby.pyc in aggregate(self, func_or_funcs, *args, **kwargs)
   2305                 return self._python_agg_general(func_or_funcs, *args, **kwargs)
   2306             except Exception:
-> 2307                 result = self._aggregate_named(func_or_funcs, *args, **kwargs)
   2308 
   2309             index = Index(sorted(result), name=self.grouper.names[0])

/usr/local/lib/python2.7/dist-packages/pandas/core/groupby.pyc in _aggregate_named(self, func, *args, **kwargs)
   2392         for name, group in self:
   2393             group.name = name
-> 2394             output = func(group, *args, **kwargs)
   2395             if isinstance(output, (Series, Index, np.ndarray)):
   2396                 raise Exception('Must produce aggregated value')

<ipython-input-174-5be8bb847fd6> in <lambda>(x)
----> 1 clusters.agg({'diffs': lambda x: x.quantile(.5)})

/usr/local/lib/python2.7/dist-packages/pandas/core/series.pyc in quantile(self, q)
   1264                 return _quantile(values, qs*100)
   1265 
-> 1266         return self._maybe_box(lambda values: multi(values, q), dropna=True)
   1267 
   1268     def ptp(self, axis=None, out=None):

/usr/local/lib/python2.7/dist-packages/pandas/core/series.pyc in _maybe_box(self, func, dropna)
   2105 
   2106             if len(values) == 0:
-> 2107                 return boxer(iNaT)
   2108 
   2109             values = values.view('i8')

NameError: global name 'iNaT' is not defined

Looks like other references to iNaT are all tslib.iNaT.

https://github.com/pydata/pandas/blob/master/pandas/core/series.py#L2098

@TomAugspurger
Copy link
Contributor

could you show your pandas version (pd.show_versions()). Also how did you install pandas?

@jreback
Copy link
Contributor

jreback commented Mar 19, 2015

yep, looks like an untested case. (fix is trivial, just use tslib.iNaT, but needs tests

In [1]: Series([]).quantile(.5)
Out[1]: nan

In [2]: Series([],dtype='M8[ns]').quantile(.5)
NameError: global name 'iNaT' is not defined

In [3]: Series([],dtype='m8[ns]').quantile(.5)
NameError: global name 'iNaT' is not defined

@jreback jreback added the Bug label Mar 19, 2015
@jreback jreback added this to the 0.16.1 milestone Mar 19, 2015
jreback pushed a commit that referenced this issue Mar 25, 2015
Changes to be committed:
	modified:   pandas/core/series.py
	modified:   pandas/tests/test_series.py

Fixes global reference to iNaT (should be tslib.iNaT) in series._maybe_box.
Adds test `test_datetime_timedelta_quantiles` to check for proper return value
in test_series.py.

Issue #9675
@jreback
Copy link
Contributor

jreback commented Mar 25, 2015

closed by #9694

@jreback jreback closed this as completed Mar 25, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants