Skip to content
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

CLN: clean-up sanitize_array series construction #26979

Merged

Conversation

jorisvandenbossche
Copy link
Member

Some possible clean-up that I encountered when doing #26848

@codecov
Copy link

codecov bot commented Jun 21, 2019

Codecov Report

Merging #26979 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #26979      +/-   ##
==========================================
- Coverage   91.98%   91.97%   -0.01%     
==========================================
  Files         180      180              
  Lines       50760    50754       -6     
==========================================
- Hits        46690    46682       -8     
- Misses       4070     4072       +2
Flag Coverage Δ
#multiple 90.57% <100%> (ø) ⬆️
#single 41.84% <56.25%> (-0.09%) ⬇️
Impacted Files Coverage Δ
pandas/core/internals/construction.py 96.41% <100%> (+0.45%) ⬆️
pandas/io/gbq.py 88.88% <0%> (-11.12%) ⬇️
pandas/core/frame.py 96.89% <0%> (-0.12%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c275dbf...1f7c446. Read the comment docs.

@codecov
Copy link

codecov bot commented Jun 21, 2019

Codecov Report

Merging #26979 into master will increase coverage by 0.14%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #26979      +/-   ##
==========================================
+ Coverage   91.84%   91.99%   +0.14%     
==========================================
  Files         180      180              
  Lines       50734    50768      +34     
==========================================
+ Hits        46599    46705     +106     
+ Misses       4135     4063      -72
Flag Coverage Δ
#multiple 90.63% <100%> (+0.15%) ⬆️
#single 41.83% <58.82%> (-0.13%) ⬇️
Impacted Files Coverage Δ
pandas/core/internals/construction.py 96.41% <100%> (+0.35%) ⬆️
pandas/io/gbq.py 88.88% <0%> (-11.12%) ⬇️
pandas/core/internals/blocks.py 94.38% <0%> (-0.77%) ⬇️
pandas/core/arrays/integer.py 96.3% <0%> (-0.64%) ⬇️
pandas/core/dtypes/concat.py 96.58% <0%> (-0.46%) ⬇️
pandas/core/internals/concat.py 96.48% <0%> (-0.37%) ⬇️
pandas/core/arrays/sparse.py 94.19% <0%> (-0.31%) ⬇️
pandas/core/internals/managers.py 96% <0%> (-0.22%) ⬇️
pandas/core/indexes/numeric.py 97.34% <0%> (-0.13%) ⬇️
... and 26 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update de0867f...634c820. Read the comment docs.

subarr = data.copy()
else:
subarr = _try_cast(data, True, dtype, copy, raise_cast_failure)
elif isinstance(data, Index):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was already checked above that data is an ndarray, so can never be an index


elif isinstance(data, ExtensionArray):
if isinstance(data, ABCPandasArray):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The extract_array(data, extract_numpy=True) above already did this

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. small comments.

subarr = np.array(data, copy=False)

if (dtype is not None
and is_float_dtype(data.dtype) and is_integer_dtype(dtype)):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

future cleanup is to remove this and condition (as I think _try_cast already handles this)

if dtype is not None:
subarr = data.astype(dtype)

subarr = subarr.astype(dtype)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add copy=False here (not sure if it matters but can't hurt)

@@ -677,10 +657,10 @@ def sanitize_array(data, index, dtype=None, copy=False,
return subarr


def _try_cast(arr, take_fast_path, dtype, copy, raise_cast_failure):
def _try_cast(arr, dtype, copy, raise_cast_failure):

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you try to doc-string / type this?

@jreback jreback added the Clean label Jun 21, 2019
@@ -677,10 +657,22 @@ def sanitize_array(data, index, dtype=None, copy=False,
return subarr


def _try_cast(arr, take_fast_path, dtype, copy, raise_cast_failure):

def _try_cast(arr, dtype, copy, raise_cast_failure):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add types here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice removing the fast path arg!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jorisvandenbossche can you add types here?

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, if you can add types to _try_cast would be great. merge on green.

@jreback jreback added this to the 0.25.0 milestone Jun 21, 2019

Parameters
----------
arr : array-like
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any restriction on ndim? Some of these functions are only called via the dataframe constructor.

@jreback
Copy link
Contributor

jreback commented Jun 27, 2019

@jbrockmendel ok with this?

@jbrockmendel
Copy link
Member

yep

@jreback jreback merged commit cfb9bbe into pandas-dev:master Jun 28, 2019
@jreback
Copy link
Contributor

jreback commented Jun 28, 2019

thanks @jorisvandenbossche

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants