10000 BUG-22984 Fix truncation of DataFrame representations by JustinZhengBC · Pull Request #22987 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

BUG-22984 Fix truncation of DataFrame representations #22987

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

Merged
merged 124 commits into from
Nov 15, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
124 commits
Select commit Hold shift + click to select a range
eb4a239
BUG-22984 Fix truncation of DataFrame representations
JustinZhengBC Oct 4, 2018
8e82c82
BUG-22984 Fix flake8 issues
JustinZhengBC Oct 4, 2018
448153d
BUG-22984 Fix whatsnew and add test
JustinZhengBC Oct 6, 2018
244b295
BUG-22984 Fix whatsnew and add test
JustinZhengBC Oct 6, 2018
aa867b0
BUG-22984 Fix linting issue
JustinZhengBC Oct 7, 2018
34b464f
DOC: Updating the docstring of Series.dot (#22890)
HubertKl Nov 3, 2018
4629504
Fixing flake8 problems new to flake8 3.6.0 (#23472)
datapythonista Nov 3, 2018
696e8c7
strictness and checks for Timedelta _simple_new (#23433)
jbrockmendel Nov 3, 2018
3faf1a9
REF: cython cleanup, typing, optimizations (#23464)
jbrockmendel Nov 3, 2018
126edd9
ENH: Add FrozenList.union and .difference (#23394)
gfyoung Nov 3, 2018
da08eeb
BUG: Allow freq conversion from dt64 to period (#23460)
TomAugspurger Nov 3, 2018
29239ad
add number of Errors, Warnings to scripts/validate_docstrings.py (#23…
hongshaoyang Nov 3, 2018
90be7b3
DOC: Add cookbook entry for triangular correlation matrix (GH22840) (…
Nov 3, 2018
defff22< 8000 /code>
CLN: doc string (#23469)
topper-123 Nov 3, 2018
7aed9e6
STYLE: Standardize cython spacing for casting, with linting (#23474)
jbrockmendel Nov 4, 2018
f1768c7
DOC: Adding documentation for pandas.core.indexes.api internal functi…
Nov 4, 2018
547c240
DOC: Clarify documentation of 'ambiguous' parameter (#23408)
bartaelterman Nov 4, 2018
cb51a02
DOC: Validate in docstrings that numpy and pandas are not imported (#…
thoo Nov 4, 2018
ae938fd
DOC: Updated docstrings related to DateTimeIndex. GH22459 (#22504)
eldritchideen Nov 4, 2018
8c29ede
DOC: Rephrased doc for Series.asof. Added examples (#21034)
dragosthealex Nov 4, 2018
b0c4156
TST: drop tz-aware timestamp from DatetimIndex with DST transition (#…
mroeschke Nov 4, 2018
23fae32
DOC: update the pandas.Series.shift docstring (#20472)
ZackStone Nov 4, 2018
1f4bad5
Isort contributing guide (#23364)
alimcmaster1 Nov 4, 2018
e938ed4
API: fix corner case of lib.infer_dtype (#23422)
h-vetinari Nov 4, 2018
39a2e0a
DOC: Use flake8 to check for PEP8 violations in doctests (#23399)
FHaase Nov 4, 2018
1b00ec5
TST: Empty Series.reindex with tz-aware dtype (#23480)
mroeschke Nov 4, 2018
0d0b561
DOC: Fix creation of [source] links in the doc creation (#23129)
vkk800 Nov 4, 2018
6202eb0
DOC: Remove dead link and update links to https (#23476)
mroeschke Nov 5, 2018
58dc180
DOC: Fix DataFrame.nlargest and DataFrame.nsmallest doctests (#23202)
Moisan Nov 5, 2018
55e2f3d
DOC: Fix syntax error in groupby docs (#23498)
gfyoung Nov 5, 2018
5e09698
Run Isort on tests-> util,sereis,arrays (#23501)
thoo Nov 5, 2018
ed46d6d
TST: Add test of assignment chaining and dupe cols (#23487)
gfyoung Nov 5, 2018
c3f6b8b
BUG: Avoid casting to double type unnecessarily when setting values i…
icexelloss Nov 5, 2018
9a77c2f
Bumping up min version for pyarrow and fastparquet (#23482)
anjsudh Nov 5, 2018
feede99
CI: Fixed pytest minversion (#23520)
TomAugspurger Nov 6, 2018
32c22d4
CI: Exclude asv benchmark envs from flake8 checks (#23497)
qwhelan Nov 6, 2018
b34cfff
Extraneous parts broken off from other PRS (#23518)
jbrockmendel Nov 6, 2018
53dad83
Fixing typo in cython casting lint, and making it azure friendly (#23…
datapythonista Nov 6, 2018
510ba4e
CI: Unpin NumPy (#23465)
TomAugspurger Nov 6, 2018
6a88f0e
TST: Add test for mangling of unnamed columns (#23485)
gfyoung Nov 6, 2018
37dd36f
PERF: cython optimizations (#23477)
jbrockmendel Nov 6, 2018
2b626d5
BUG: Cleanup timedelta offset (#23439)
sinhrks Nov 6, 2018
9436e21
API: change default for sep in str.cat (in docstring) (#23443)
h-vetinari Nov 6, 2018
1071c28
BUG: fix df.where(cond) when cond is empty (#21947)
pajachiet Nov 6, 2018
079f632
BUG: Fix of handle missing CSV MI column names (#23484)
gfyoung Nov 6, 2018
013315a
BUG GH23451 Allow setting date in string index for Series (#23495)
JustinZhengBC Nov 6, 2018
662759a
BUG: fix groupby.transform rename bug (#23461) (#23463)
DiegoAlbertoTorres Nov 6, 2018
6efd331
BUG: GroupBy return EA dtype (#23318)
5hirish Nov 6, 2018
1da1d63
BUG - pd.concat with all Series on axis=1 ignores the `names` argumen…
ms7463 Nov 6, 2018
2acb22c
BUG: names on union and intersection for Index were inconsistent (#19…
Dr-Irv Nov 6, 2018
898c2a2
DOC/TST: Fix warning in concat docstring (#23529)
TomAugspurger Nov 6, 2018
fa8e130
CI: Moving CI dependencies to "ci/deps" (#23526)
datapythonista Nov 6, 2018
278124e
Fix+test timedelta64(nat) ops (#23425)
jbrockmendel Nov 6, 2018
863e628
CLN: Isort io and compat dirs (#23534)
alimcmaster1 Nov 7, 2018
5244647
CI: Fail Azure CI for failing tests (#23454) 8000
alimcmaster1 Nov 7, 2018
c611272
Make validate_docstrings.py ready for the CI (#23514)
datapythonista Nov 7, 2018
4d4b583
Fixing bug in validate_docstrings.py, where a bracket closed in the w…
datapythonista Nov 7, 2018
8c280ca
BUG: Timestamp retains frequency of input Timestamps (#23503)
mroeschke Nov 7, 2018
574a03a
BUG: DatetimeIndex slicing with boolean Index raises TypeError (#22852)
sinhrks Nov 7, 2018
73cc01b
BUG: Return KeyError for invalid string key (#23540)
toobaz Nov 7, 2018
43b135f
TST: coverage for skipped tests in io/formats/test_to_html.py (#22888)
simonjayhawkins Nov 7, 2018
31eee47
DOC: Updating DataFrame.join docstring (#23471)
datapythonista Nov 7, 2018
737cb7d
ENH: Support EAs in Series.unstack (#23284)
TomAugspurger Nov 7, 2018
13f41ae
BUG: Fix error message for invalid HTML flavor (#23550)
gfyoung Nov 8, 2018
6d4178a
remove uses of (ts)?lib.(NaT|iNaT|Timestamp) (#23562)
jbrockmendel Nov 8, 2018
66a95bc
BUG: raise if invalid freq is passed (#23546)
toobaz Nov 8, 2018
3bb2f75
TST: Fix dtype mismatch on 32bit in IntervalTree get_indexer test (#2…
jschendel Nov 8, 2018
af33308
Preserve EA dtype in DataFrame.stack (#23285)
TomAugspurger Nov 8, 2018
cf5e385
CI: Auto-cancel redundant builds (#23523)
TomAugspurger Nov 8, 2018
7c0b5d0
ENH: Support writing timestamps with timezones with to_sql (#22654)
mroeschke Nov 8, 2018
db58d3d
DOC: Added note about groupby excluding Decimal columns by default (#…
Nov 8, 2018
b62634f
Fixes to make validate_docstrings.py not generate warnings or unwante…
datapythonista Nov 8, 2018
2c193a0
Update description of Index._values/values/ndarray_values (#23507)
jorisvandenbossche Nov 8, 2018
6244f35
TST: Tests and Helpers for Datetime/Period Arrays (#23502)
jbrockmendel Nov 9, 2018
03d632c
PERF: define is_all_dates to shortcut inadvertent copy when slicing a…
qwhelan Nov 9, 2018
01ffb03
PERF: Speeds up creation of Period, PeriodArray, with Offset freq (#2…
TomAugspurger Nov 9, 2018
56b8024
DOC/CI: Add linting to rst files, and fix issues (#23381)
FHaase Nov 9, 2018
84ef701
CLN: remove values attribute from datetimelike EAs (#23603)
jorisvandenbossche Nov 9, 2018
e4104e9
TST: Use intp as expected dtype in IntervalIndex indexing tests (#23609)
jschendel Nov 10, 2018
eefb76e
ENH: Support for partition_cols in to_parquet (#23321)
anjsudh Nov 10, 2018
af8ca26
DOC: Updating Series.resample and DataFrame.resample docstrings (#23197)
jmrr Nov 10, 2018
d8d6222
MAINT: tm.assert_raises_regex --> pytest.raises (#23592)
gfyoung Nov 10, 2018
cffdb0e
DOC: Remove incorrect periods at the end of parameter types (#23600)
meiermark Nov 11, 2018
b265308
DOC: Fixes to docstring to add validation to CI (#23560)
datapythonista Nov 11, 2018
f2eac44
TST: Fix integer ops comparison test (#23619)
TomAugspurger Nov 11, 2018
fef6d7a
TST: Unskip some Categorical Tests (#23613)
TomAugspurger Nov 11, 2018
c80ff12
DOC: Fix Order of parameters in docstrings (#23611)
thoo Nov 11, 2018
ff8130b
CLN: use float64_t consistently instead of double, double_t (#23583)
jbrockmendel Nov 11, 2018
9977a08
API: DataFrame.__getitem__ returns Series for sparse column (#23561)
TomAugspurger Nov 11, 2018
1d861de
BUG: Delegate more of Excel parsing to CSV (#23544)
gfyoung Nov 11, 2018
c355f26
BUG: Casting tz-aware DatetimeIndex to object-dtype ndarray/Index (#2…
jbrockmendel Nov 11, 2018
a4c1490
BUG/REF: TimedeltaIndex.__new__ (#23539)
jbrockmendel Nov 11, 2018
468df9c
BUILD: Simplifying contributor dependencies (#23522)
datapythonista Nov 11, 2018
6401a4f
TST: Fix xfailing DataFrame arithmetic tests by transposing (#23620)
jbrockmendel Nov 12, 2018
92b015d
DOC: Enhancing pivot / reshape docs (#21038)
VincentLa Nov 12, 2018
519de0b
CLN 8000 :Remove unused **kwargs from user facing methods (#23249)
kprestel Nov 12, 2018
d4be020
CI: Check in the CI that assert_raises_regex is not being used (#23627)
datapythonista Nov 12, 2018
d8826bf
CLN: datetimelike arrays: isort, small reorg (#23587)
jbrockmendel Nov 12, 2018
3b87703
BUG: astype fill_value for SparseArray.astype (#23547)
TomAugspurger Nov 12, 2018
999ef43
More helpful Stata string length error. (#23629)
jtkiley Nov 12, 2018
7fc3732
DEPR: Deprecate usecols as int in read_excel (#23635)
gfyoung Nov 12, 2018
bb9f4eb
BUG: Don't over-optimize memory with jagged CSV (#23527)
gfyoung Nov 12, 2018
76c078c
DOC: Adding validation of the section order in docstrings (#23607)
datapythonista Nov 12, 2018
fdda5d7
CLN: remove incorrect usages of com.AbstractMethodError (#23625)
jbrockmendel Nov 12, 2018
d3e43f8
DOC: avoid SparseArray.take error (#23637)
TomAugspurger Nov 12, 2018
c7dc40c
DOC: clean-up recent doc errors/warnings (#23636)
jorisvandenbossche Nov 12, 2018
f7556a4
DOC: Fix name of the See Also section titles in docstrings (#23653)
gueletk Nov 13, 2018
951041e
CI: Allow to compile docs with ipython 7.11 #22990 (#23655)
benoxoft Nov 13, 2018
d5d6d91
TST: IntervalTree.get_loc_interval should return platform int (#23660)
jschendel Nov 13, 2018
4242077
CLN: Move to_excel to generic.py (#23656)
gfyoung Nov 13, 2018
c1640c6
Add to_flat_index method to MultiIndex (#22866)
WillAyd Nov 13, 2018
8e4bf4c
BUG: Fix read_excel w/parse_cols & empty dataset (#23661)
gfyoung Nov 13, 2018
b3a3ac7
DOC: Update is_sparse docstring (#19983)
sechilds Nov 13, 2018
7dab45f
DOC: Surface / doc mangle_dupe_cols in read_excel (#23678)
gfyoung Nov 14, 2018
991547e
Fix errorbar visualization (#23674)
justinchan23 Nov 14, 2018
c8ac3bf
DOC: Accessing files from a S3 bucket. (#23639)
myles Nov 14, 2018
f9563ea
REF: Move Excel names parameter handling to CSV (#23690)
gfyoung Nov 14, 2018
2688cbe
BUG: Fix Series/DataFrame.rank(pct=True) with more than 2**24 rows (#…
jschendel Nov 14, 2018
d0adfb0
CI: raise clone depth limit on CI
jreback Nov 14, 2018
f452c40
Implement _most_ of the EA interface for DTA/TDA (#23643)
jbrockmendel Nov 14, 2018
36f0608
Merge master
JustinZhengBC Nov 14, 2018
8459936
reapply changes
JustinZhengBC Nov 14, 2018
0f7aa4b
r
JustinZhengBC Nov 14, 2018
82fa50c
Merge remote-tracking branch 'upstream/master' into JustinZhengBC-BUG…
TomAugspurger Nov 14, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Implement _most_ of the EA interface for DTA/TDA (#23643)
  • Loading branch information
jbrockmendel authored and JustinZhengBC committed Nov 14, 2018
commit f452c40323e0fdabf7a667d3d018d7f33c956144
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v0.24.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,8 @@ Notice how we now instead output ``np.nan`` itself instead of a stringified form
- :func:`read_sas()` will correctly parse sas7bdat files with data page types having also bit 7 set (so page type is 128 + 256 = 384) (:issue:`16615`)
- Bug in :meth:`detect_client_encoding` where potential ``IOError`` goes unhandled when importing in a mod_wsgi process due to restricted access to stdout. (:issue:`21552`)
- Bug in :func:`to_string()` that broke column alignment when ``index=False`` and width of first column's values is greater than the width of first column's header (:issue:`16839`, :issue:`13032`)
- Bug in :func:`DataFrame.to_string()` that broke column alignment when ``index=False`` and width of first column's values is greater than the width of first column's header (:issue:`16839`, :issue:`13032`)
- Bug in :func:`DataFrame.to_string()` that caused representations of :class:`DataFrame` to not take up the whole window (:issue:`22984`)
- Bug in :func:`DataFrame.to_csv` where a single level MultiIndex incorrectly wrote a tuple. Now just the value of the index is written (:issue:`19589`).
- Bug in :meth:`HDFStore.append` when appending a :class:`DataFrame` with an empty string column and ``min_itemsize`` < 8 (:issue:`12242`)
- Bug in :func:`to_string()` that caused representations of :class:`DataFrame` to not take up the whole window (:issue:`22984`)
Expand Down
63 changes: 62 additions & 1 deletion pandas/core/arrays/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from pandas.core.dtypes.missing import isna

import pandas.core.common as com
from pandas.core.algorithms import checked_add_with_arr
from pandas.core.algorithms import checked_add_with_arr, take, unique1d

from .base import ExtensionOpsMixin
from pandas.util._decorators import deprecate_kwarg
Expand Down Expand Up @@ -196,6 +196,67 @@ def astype(self, dtype, copy=True):
return self._box_values(self.asi8)
return super(DatetimeLikeArrayMixin, self).astype(dtype, copy)

# ------------------------------------------------------------------
# ExtensionArray Interface
# TODO:
# * _from_sequence
# * argsort / _values_for_argsort
# * _reduce

def unique(self):
result = unique1d(self.asi8)
return type(self)(result, dtype=self.dtype)

def _validate_fill_value(self, fill_value):
"""
If a fill_value is passed to `take` convert it to an i8 representation,
raising ValueError if this is not possible.

Parameters
----------
fill_value : object

Returns
-------
fill_value : np.int64

Raises
------
ValueError
"""
raise AbstractMethodError(self)

def take(self, indices, allow_fill=False, fill_value=None):
if allow_fill:
fill_value = self._validate_fill_value(fill_value)

new_values = take(self.asi8,
indices,
allow_fill=allow_fill,
fill_value=fill_value)

return type(self)(new_values, dtype=self.dtype)

@classmethod
def _concat_same_type(cls, to_concat):
dtypes = {x.dtype for x in to_concat}
assert len(dtypes) == 1
dtype = list(dtypes)[0]

values = np.concatenate([x.asi8 for x in to_concat])
return cls(values, dtype=dtype)

def copy(self, deep=False):
values = self.asi8.copy()
return type(self)(values, dtype=self.dtype, freq=self.freq)

def _values_for_factorize(self):
return self.asi8, iNaT

@classmethod
def _from_factorized(cls, values, original):
return cls(values, dtype=original.dtype)

# ------------------------------------------------------------------
# Null Handling

Expand Down
28 changes: 23 additions & 5 deletions pandas/core/arrays/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
conversion, fields, timezones,
resolution as libresolution)

from pandas.util._decorators import cache_readonly
from pandas.util._decorators import cache_readonly, Appender
from pandas.errors import PerformanceWarning
from pandas import compat

Expand All @@ -21,8 +21,7 @@
is_object_dtype,
is_int64_dtype,
is_datetime64tz_dtype,
is_datetime64_dtype,
ensure_int64)
is_datetime64_dtype)
from pandas.core.dtypes.dtypes import DatetimeTZDtype
from pandas.core.dtypes.missing import isna
from pandas.core.dtypes.generic import ABCIndexClass, ABCSeries
Expand Down Expand Up @@ -294,7 +293,7 @@ def _generate_range(cls, start, end, periods, freq, tz=None,

if tz is not None and index.tz is None:
arr = conversion.tz_localize_to_utc(
ensure_int64(index.values),
index.asi8,
tz, ambiguous=ambiguous)

index = cls(arr)
Expand All @@ -317,7 +316,7 @@ def _generate_range(cls, start, end, periods, freq, tz=None,
if not right_closed and len(index) and index[-1] == end:
index = index[:-1]

return cls._simple_new(index.values, freq=freq, tz=tz)
return cls._simple_new(index.asi8, freq=freq, tz=tz)

# -----------------------------------------------------------------
# Descriptive Properties
Expand Down Expand Up @@ -419,6 +418,25 @@ def __iter__(self):
for v in converted:
yield v

# ----------------------------------------------------------------
# ExtensionArray Interface

@property
def _ndarray_values(self):
return self._data

@Appender(dtl.DatetimeLikeArrayMixin._validate_fill_value.__doc__)
def _validate_fill_value(self, fill_value):
if isna(fill_value):
fill_value = iNaT
elif isinstance(fill_value, (datetime, np.datetime64)):
self._assert_tzawareness_compat(fill_value)
fill_value = Timestamp(fill_value).value
else:
raise ValueError("'fill_value' should be a Timestamp. "
"Got '{got}'.".format(got=fill_value))
return fill_value

# -----------------------------------------------------------------
# Comparison Methods

Expand Down
56 changes: 14 additions & 42 deletions pandas/core/arrays/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,6 @@ def _from_sequence(cls, scalars, dtype=None, copy=False):
ordinals = libperiod.extract_ordinals(periods, freq)
return cls(ordinals, freq=freq)

def _values_for_factorize(self):
return self.asi8, iNaT

@classmethod
def _from_factorized(cls, values, original):
# type: (Sequence[Optional[Period]], PeriodArray) -> PeriodArray
return cls(values, freq=original.freq)

@classmethod
def _from_datetime64(cls, data, freq, tz=None):
"""Construct a PeriodArray from a datetime64 array
Expand Down Expand Up @@ -262,14 +254,6 @@ def _generate_range(cls, start, end, periods, freq, fields):

return subarr, freq

@classmethod
def _concat_same_type(cls, to_concat):
freq = {x.freq for x in to_concat}
assert len(freq) == 1
freq = list(freq)[0]
values = np.concatenate([x._data for x in to_concat])
return cls(values, freq=freq)

# --------------------------------------------------------------------
# Data / Attributes

Expand Down Expand Up @@ -415,29 +399,20 @@ def __setitem__(
raise TypeError(msg)
self._data[key] = value

def take(self, indices, allow_fill=False, fill_value=None):
if allow_fill:
if isna(fill_value):
fill_value = iNaT
elif isinstance(fill_value, Period):
if self.freq != fill_value.freq:
msg = DIFFERENT_FREQ_INDEX.format(
self.freq.freqstr,
fill_value.freqstr
)
raise IncompatibleFrequency(msg)

fill_value = fill_value.ordinal
else:
msg = "'fill_value' should be a Period. Got '{}'."
raise ValueError(msg.format(fill_value))

new_values = algos.take(self._data,
indices,
allow_fill=allow_fill,
fill_value=fill_value)

return type(self)(new_values, self.freq)
@Appender(dtl.DatetimeLikeArrayMixin._validate_fill_value.__doc__)
def _validate_fill_value(self, fill_value):
if isna(fill_value):
fill_value = iNaT
elif isinstance(fill_value, Period):
if fill_value.freq != self.freq:
msg = DIFFERENT_FREQ_INDEX.format(self.freq.freqstr,
fill_value.freqstr)
raise IncompatibleFrequency(msg)
fill_value = fill_value.ordinal
else:
raise ValueError("'fill_value' should be a Period. "
"Got '{got}'.".format(got=fill_value))
return fill_value

def fillna(self, value=None, method=None, limit=None):
# TODO(#20300)
Expand Down Expand Up @@ -474,9 +449,6 @@ def fillna(self, value=None, method=None, limit=None):
new_values = self.copy()
return new_values

def copy(self, deep=False):
return type(self)(self._data.copy(), freq=self.freq)

def value_counts(self, dropna=False):
from pandas import Series, PeriodIndex

Expand Down
14 changes: 13 additions & 1 deletion pandas/core/arrays/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from pandas._libs.tslibs.fields import get_timedelta_field
from pandas._libs.tslibs.timedeltas import (
array_to_timedelta64, parse_timedelta_unit)
from pandas.util._decorators import Appender

from pandas import compat

Expand Down Expand Up @@ -139,7 +140,7 @@ def _simple_new(cls, values, freq=None, dtype=_TD_DTYPE):
result._freq = freq
return result

def __new__(cls, values, freq=None):
def __new__(cls, values, freq=None, dtype=_TD_DTYPE):

freq, freq_infer = dtl.maybe_infer_freq(freq)

Expand Down Expand Up @@ -193,6 +194,17 @@ def _generate_range(cls, start, end, periods, freq, closed=None):
# ----------------------------------------------------------------
# Array-Like / EA-Interface Methods

@Appender(dtl.DatetimeLikeArrayMixin._validate_fill_value.__doc__)
def _validate_fill_value(self, fill_value):
if isna(fill_value):
fill_value = iNaT
elif isinstance(fill_value, (timedelta, np.timedelta64, Tick)):
fill_value = Timedelta(fill_value).value
else:
raise ValueError("'fill_value' should be a Timedelta. "
"Got '{got}'.".format(got=fill_value))
return fill_value

# ----------------------------------------------------------------
# Arithmetic Methods

Expand Down
8 changes: 1 addition & 7 deletions pandas/core/dtypes/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,13 +476,7 @@ def _concat_datetimetz(to_concat, name=None):
all inputs must be DatetimeIndex
it is used in DatetimeIndex.append also
"""
# do not pass tz to set because tzlocal cannot be hashed
if len({str(x.dtype) for x in to_concat}) != 1:
raise ValueError('to_concat must have the same tz')
tz = to_concat[0].tz
# no need to localize because internal repr will not be changed
new_values = np.concatenate([x.asi8 for x in to_concat])
return to_concat[0]._simple_new(new_values, tz=tz, name=name)
return to_concat[0]._concat_same_dtype(to_concat, name=name)


def _concat_index_same_dtype(indexes, klass=None):
Expand Down
23 changes: 15 additions & 8 deletions pandas/core/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
is_datetime_or_timedelta_dtype, is_dtype_equal, is_float, is_float_dtype,
is_integer, is_integer_dtype, is_list_like, is_object_dtype,
is_period_dtype, is_scalar, is_string_dtype)
import pandas.core.dtypes.concat as _concat
from pandas.core.dtypes.generic import ABCIndex, ABCIndexClass, ABCSeries
from pandas.core.dtypes.missing import isna

Expand Down Expand Up @@ -215,6 +214,11 @@ def ceil(self, freq, ambiguous='raise', nonexistent='raise'):
class DatetimeIndexOpsMixin(DatetimeLikeArrayMixin):
""" common ops mixin to support a unified interface datetimelike Index """

# override DatetimeLikeArrayMixin method
copy = Index.copy
unique = Index.unique
take = Index.take

# DatetimeLikeArrayMixin assumes subclasses are mutable, so these are
# properties there. They can be made into cache_readonly for Index
# subclasses bc they are immutable
Expand Down Expand Up @@ -685,17 +689,21 @@ def _concat_same_dtype(self, to_concat, name):
"""
attribs = self._get_attributes_dict()
attribs['name'] = name
# do not pass tz to set because tzlocal cannot be hashed
if len({str(x.dtype) for x in to_concat}) != 1:
raise ValueError('to_concat must have the same tz')

if not is_period_dtype(self):
# reset freq
attribs['freq'] = None

if getattr(self, 'tz', None) is not None:
return _concat._concat_datetimetz(to_concat, name)
# TODO(DatetimeArray)
# - remove the .asi8 here
# - remove the _maybe_box_as_values
# - combine with the `else` block
new_data = self._concat_same_type(to_concat).asi8
else:
new_data = np.concatenate([c.asi8 for c in to_concat])
new_data = type(self._values)._concat_same_type(to_concat)

new_data = self._maybe_box_as_values(new_data, **attribs)
return self._simple_new(new_data, **attribs)

def _maybe_box_as_values(self, values, **attribs):
Expand All @@ -704,7 +712,6 @@ def _maybe_box_as_values(self, values, **attribs):
# but others are not. When everyone is an ExtensionArray, this can
# be removed. Currently used in
# - sort_values
# - _concat_same_dtype
return values

def astype(self, dtype, copy=True):
Expand Down Expand Up @@ -761,7 +768,7 @@ def _ensure_datetimelike_to_i8(other, to_utc=False):
try:
return np.array(other, copy=False).view('i8')
except TypeError:
# period array cannot be coerces to int
# period array cannot be coerced to int
other = Index(other)
return other.asi8

Expand Down
17 changes: 7 additions & 10 deletions pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,16 +551,13 @@ def snap(self, freq='S'):
# TODO: what about self.name? if so, use shallow_copy?

def unique(self, level=None):
# Override here since IndexOpsMixin.unique uses self._values.unique
# For DatetimeIndex with TZ, that's a DatetimeIndex -> recursion error
# So we extract the tz-naive DatetimeIndex, unique that, and wrap the
# result with out TZ.
if self.tz is not None:
naive = type(self)(self._ndarray_values, copy=False)
else:
naive = self
result = super(DatetimeIndex, naive).unique(level=level)
return self._shallow_copy(result.values)
if level is not None:
self._validate_index_level(level)

# TODO(DatetimeArray): change dispatch once inheritance is removed
# call DatetimeArray method
result = DatetimeArray.unique(self)
return self._shallow_copy(result._data)

def union(self, other):
"""
Expand Down
Loading
0