-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
REF: Pieces broken off of #24024 #24364
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,7 +84,7 @@ def wrapper(self, other): | |
other = Period(other, freq=self.freq) | ||
result = op(other.ordinal) | ||
|
||
if self.hasnans: | ||
if self._hasnans: | ||
result[self._isnan] = nat_result | ||
|
||
return result | ||
|
@@ -497,7 +497,7 @@ def _time_shift(self, n, freq=None): | |
"{cls}._time_shift" | ||
.format(cls=type(self).__name__)) | ||
values = self.asi8 + n * self.freq.n | ||
if self.hasnans: | ||
if self._hasnans: | ||
values[self._isnan] = iNaT | ||
return type(self)(values, freq=self.freq) | ||
|
||
|
@@ -559,7 +559,7 @@ def asfreq(self, freq=None, how='E'): | |
|
||
new_data = period_asfreq_arr(ordinal, base1, base2, end) | ||
|
||
if self.hasnans: | ||
if self._hasnans: | ||
new_data[self._isnan] = iNaT | ||
|
||
return type(self)(new_data, freq=freq) | ||
|
@@ -579,7 +579,7 @@ def _format_native_types(self, na_rep=u'NaT', date_format=None, **kwargs): | |
else: | ||
formatter = lambda dt: u'%s' % dt | ||
|
||
if self.hasnans: | ||
if self._hasnans: | ||
mask = self._isnan | ||
values[mask] = na_rep | ||
imask = ~mask | ||
|
@@ -668,7 +668,7 @@ def _sub_period(self, other): | |
new_data = asi8 - other.ordinal | ||
new_data = np.array([self.freq * x for x in new_data]) | ||
|
||
if self.hasnans: | ||
if self._hasnans: | ||
new_data[self._isnan] = NaT | ||
|
||
return new_data | ||
|
@@ -983,7 +983,7 @@ def dt64arr_to_periodarr(data, freq, tz=None): | |
|
||
""" | ||
if data.dtype != np.dtype('M8[ns]'): | ||
raise ValueError('Wrong dtype: %s' % data.dtype) | ||
raise ValueError('Wrong dtype: {dtype}'.format(dtype=data.dtype)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
if freq is None: | ||
if isinstance(data, ABCIndexClass): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -227,11 +227,11 @@ def __new__(cls, data=None, | |
"endpoints is deprecated. Use " | ||
"`pandas.date_range` instead.", | ||
FutureWarning, stacklevel=2) | ||
result = cls._generate_range(start, end, periods, | ||
freq=freq, tz=tz, normalize=normalize, | ||
closed=closed, ambiguous=ambiguous) | ||
result.name = name | ||
return result | ||
dtarr = DatetimeArray._generate_range( | ||
start, end, periods, | ||
freq=freq, tz=tz, normalize=normalize, | ||
closed=closed, ambiguous=ambiguous) | ||
return cls(dtarr, name=name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think in #24024 this becomes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto below and for TimedeltaIndex There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it worth doing this now then, when we'll just need to change it again? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The upside is that it means the diff in 24024 is just one line. I'm OK with this either way. |
||
|
||
if is_scalar(data): | ||
raise TypeError("{cls}() must be called with a " | ||
|
@@ -1471,12 +1471,12 @@ def date_range(start=None, end=None, periods=None, freq=None, tz=None, | |
if freq is None and com._any_none(periods, start, end): | ||
freq = 'D' | ||
|
||
result = DatetimeIndex._generate_range( | ||
dtarr = DatetimeArray._generate_range( | ||
start=start, end=end, periods=periods, | ||
freq=freq, tz=tz, normalize=normalize, | ||
closed=closed, **kwargs) | ||
|
||
result.name = name | ||
result = DatetimeIndex(dtarr, name=name) | ||
return result | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,17 @@ | |
import pandas.util.testing as tm | ||
|
||
|
||
class TestTimedeltaArrayConstructor(object): | ||
def test_copy(self): | ||
data = np.array([1, 2, 3], dtype='m8[ns]') | ||
arr = TimedeltaArray(data, copy=False) | ||
assert arr._data is data | ||
|
||
arr = TimedeltaArray(data, copy=True) | ||
assert arr._data is not data | ||
assert arr._data.base is not data | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This last line is not present in the test in #24024. |
||
|
||
|
||
class TestTimedeltaArray(object): | ||
def test_from_sequence_dtype(self): | ||
msg = r"Only timedelta64\[ns\] dtype is valid" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC this is a general Index property, are changing this globally? (ok by me)