Skip to content

BUG: inconsistent median support for datetimelike dtypes #33760

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
jorisvandenbossche opened this issue Apr 24, 2020 · 1 comment · Fixed by #36694
Closed

BUG: inconsistent median support for datetimelike dtypes #33760

jorisvandenbossche opened this issue Apr 24, 2020 · 1 comment · Fixed by #36694
Labels
API - Consistency Internal Consistency of API/Behavior Bug Datetime Datetime data dtype Reduction Operations sum, mean, min, max, etc.
Milestone

Comments

@jorisvandenbossche
Copy link
Member

#29941 introduced support for taking the median of a datetime-like column.
In released version, (pandas 1.0.3) we get:

In [20]: df = pd.DataFrame({'a': pd.date_range("2012", periods=3, freq='D')})  

In [21]: df.median()    
Out[21]: Series([], dtype: float64)

In [22]: df.median(numeric_only=False)  
...
TypeError: reduction operation 'median' not allowed for this dtype

In [23]: df['a'].median()  
...
TypeError: DatetimeIndex cannot perform the operation median

on master we now allow this for DataFrame (warning it will be in the future by default, and already allow it with numeric_only=False):

In [2]: df.median()  
/home/joris/miniconda3/envs/dev/bin/ipython:1: FutureWarning: DataFrame.mean and DataFrame.median with numeric_only=None will include datetime64, datetime64tz, and PeriodDtype columns in a future version.
  #!/home/joris/miniconda3/envs/dev/bin/python
Out[2]: Series([], dtype: float64)

In [3]: df.median(numeric_only=False)  
Out[3]: 
a    2012-01-02 00:00:00
dtype: object

but for a single column it still fails:

In [4]: df['a'].median()  
...
TypeError: cannot perform median with type datetime64[ns]

So we should make this support consistent (add "median" support on DatetimeArray, so it also works for Series)

cc @jbrockmendel

@jorisvandenbossche jorisvandenbossche added Datetime Datetime data dtype Numeric Operations Arithmetic, Comparison, and Logical operations labels Apr 24, 2020
@jorisvandenbossche jorisvandenbossche added this to the 1.1 milestone Apr 24, 2020
@jorisvandenbossche jorisvandenbossche added the API - Consistency Internal Consistency of API/Behavior label Apr 24, 2020
@jbrockmendel
Copy link
Member

So we should make this support consistent (add "median" support on DatetimeArray, so it also works for Series)

+1

@mroeschke mroeschke added the Bug label May 7, 2020
@jreback jreback modified the milestones: 1.1, Contributions Welcome Jul 10, 2020
@jbrockmendel jbrockmendel added the Reduction Operations sum, mean, min, max, etc. label Sep 21, 2020
@jorisvandenbossche jorisvandenbossche removed the Numeric Operations Arithmetic, Comparison, and Logical operations label Sep 28, 2020
@jreback jreback modified the milestones: Contributions Welcome, 1.2 Oct 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API - Consistency Internal Consistency of API/Behavior Bug Datetime Datetime data dtype Reduction Operations sum, mean, min, max, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants