-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: series timedelta arithmetic is not being converted to ns with numpy 1.6 #4138
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
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,9 +47,6 @@ | |
|
||
__all__ = ['Series', 'TimeSeries'] | ||
|
||
_np_version = np.version.short_version | ||
_np_version_under1p6 = LooseVersion(_np_version) < '1.6' | ||
_np_version_under1p7 = LooseVersion(_np_version) < '1.7' | ||
|
||
_SHOW_WARNINGS = True | ||
|
||
|
@@ -104,8 +101,7 @@ def convert_to_array(values): | |
elif inferred_type in set(['timedelta','timedelta64']): | ||
# need to convert timedelta to ns here | ||
# safest to convert it to an object arrany to process | ||
if not (isinstance(values, pa.Array) and com.is_timedelta64_dtype(values)): | ||
values = com._possibly_cast_to_timedelta(values) | ||
values = com._possibly_cast_to_timedelta(values) | ||
elif inferred_type in set(['integer']): | ||
if values.dtype.kind == 'm': | ||
values = values.astype('timedelta64[ns]') | ||
|
@@ -126,7 +122,7 @@ def convert_to_array(values): | |
if is_datetime_lhs and name != '__sub__': | ||
raise TypeError("can only operate on a datetimes for subtraction, " | ||
"but the operator [%s] was passed" % name) | ||
elif is_timedelta_lhs and name not in ['__add__','__sub__']: | ||
elif is_timedelta_lhs and name not in ['__add__', '__sub__']: | ||
raise TypeError("can only operate on a timedeltas for " | ||
"addition and subtraction, but the operator [%s] was passed" % name) | ||
|
||
|
@@ -143,13 +139,13 @@ def wrap_results(x): | |
# datetime and timedelta | ||
elif (is_timedelta_lhs and is_datetime_rhs) or (is_timedelta_rhs and is_datetime_lhs): | ||
|
||
if name not in ['__add__','__sub__']: | ||
if name not in ['__add__', '__sub__']: | ||
raise TypeError("can only operate on a timedelta and a datetime for " | ||
"addition and subtraction, but the operator [%s] was passed" % name) | ||
dtype = 'M8[ns]' | ||
|
||
else: | ||
raise ValueError('cannot operate on a series with out a rhs ' | ||
raise ValueError('cannot operate on a series without a rhs ' | ||
'of a series/ndarray of type datetime64[ns] ' | ||
'or a timedelta') | ||
|
||
|
@@ -291,8 +287,7 @@ def _radd_compat(left, right): | |
try: | ||
output = radd(left, right) | ||
except TypeError: | ||
cond = (_np_version_under1p6 and | ||
left.dtype == np.object_) | ||
cond = com._np_version_under1p6 and left.dtype == np.object_ | ||
if cond: # pragma: no cover | ||
output = np.empty_like(left) | ||
output.flat[:] = [radd(x, right) for x in left.flat] | ||
|
@@ -806,8 +801,13 @@ def abs(self): | |
abs: type of caller | ||
""" | ||
obj = np.abs(self) | ||
obj = com._possibly_cast_to_timedelta(obj, coerce=False) | ||
return obj | ||
return self._constructor(obj, name=self.name) | ||
|
||
def __array_wrap__(self, out, ctx=None): | ||
if (com._np_version_under1p7 and out.dtype.kind == 'm' and | ||
out.dtype != _TD_DTYPE): | ||
out = out.view('i8').astype(_TD_DTYPE) | ||
return pa.Array.__array_wrap__(self, out, ctx) | ||
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. and this fixes an issue with numpy 1.6's inability to do anything sane with |
||
|
||
def __setitem__(self, key, value): | ||
try: | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
this fixes the 1.7 issue that @jreback reported