[ 
https://issues.apache.org/jira/browse/CLIMATE-789?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15271098#comment-15271098
 ] 

ASF GitHub Bot commented on CLIMATE-789:
----------------------------------------

GitHub user jarifibrahim opened a pull request:

    https://github.com/apache/climate/pull/337

    Remove redundant code in temporal_resolution function

    Fixes https://issues.apache.org/jira/browse/CLIMATE-789

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/jarifibrahim/climate CLIMATE-789

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/climate/pull/337.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #337
    
----

----


> Remove redundant code in temporal_resolution function
> -----------------------------------------------------
>
>                 Key: CLIMATE-789
>                 URL: https://issues.apache.org/jira/browse/CLIMATE-789
>             Project: Apache Open Climate Workbench
>          Issue Type: Task
>          Components: general
>            Reporter: Ibrahim Jarif
>            Assignee: Ibrahim Jarif
>            Priority: Trivial
>              Labels: easyfix
>
> *Last 8 lines (ValueError Exception condition)* of *temporal_resolution* 
> function of *dataset.py* are redundant. The condition never occurs as the 
> *times* variable is of type *DateTime*. All the cases are handled by the *if 
> and elif*. There is no need for the *else* clause.
> {code}
> def temporal_resolution(self):
>   sorted_times = numpy.sort(self.times)
>   time_resolution = sorted_times[1] - sorted_times[0]
>   num_days = time_resolution.days
>   if num_days == 0:
>     num_hours = time_resolution.seconds / 3600
>     time_resolution = 'hourly' if num_hours >= 1 else 'minutely'
>   elif num_days == 1:
>     time_resolution = 'daily'
>   elif num_days <= 31:
>     time_resolution = 'monthly'
>   elif num_days > 31:
>     time_resolution = 'yearly'
>   else:
>     error = (
>         "Unable to calculate the temporal resolution for the "
>         "dataset. The number of days between two time values is "
>         "an unexpected value: " + str(num_days)
>     )
>     logger.error(error)
>     raise ValueError(error)
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to