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: Remove type definitions from pandas.compat #25903

Merged
merged 4 commits into from
Mar 29, 2019

Conversation

jschendel
Copy link
Member

Removes the following:

  • string_types
  • text_types
  • binary_types
  • string_and_binary_types
  • strlen
    • only used once and in PY3 is equivalent to len, so just directly called len
  • east_asian_len
    • only called by EastAsianTextAdjustment.len in pandas/io/formats/format.py
    • directly implemented as EastAsianTextAdjustment.len instead

@jschendel jschendel added 2/3 Compat Strings String extension data type and string data Clean labels Mar 28, 2019
@jschendel jschendel added this to the 0.25.0 milestone Mar 28, 2019
@jschendel
Copy link
Member Author

Note that these changes now reduce the is_string_like function in pandas/core/dtypes/inference.py to simply be isinstance(obj, str):

def is_string_like(obj):
"""
Check if the object is a string.
Parameters
----------
obj : The object to check
Examples
--------
>>> is_string_like("foo")
True
>>> is_string_like(1)
False
Returns
-------
is_str_like : bool
Whether `obj` is a string or not.
"""
return isinstance(obj, str)

Does it make sense to deprecate is_string_like and convert all existing references to the isinstance check as a followup?

@WillAyd
Copy link
Member

WillAyd commented Mar 28, 2019

I would be +1 on replacing that function with isinstance checks - if anything I think it will make static code analysis cleaner

pandas/core/base.py Show resolved Hide resolved
pandas/core/internals/blocks.py Outdated Show resolved Hide resolved
pandas/io/parsers.py Outdated Show resolved Hide resolved
pandas/tests/frame/test_dtypes.py Outdated Show resolved Hide resolved
pandas/tests/series/test_dtypes.py Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Mar 28, 2019

Codecov Report

Merging #25903 into master will increase coverage by 0.02%.
The diff coverage is 94.14%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #25903      +/-   ##
==========================================
+ Coverage   91.53%   91.56%   +0.02%     
==========================================
  Files         175      175              
  Lines       52808    52747      -61     
==========================================
- Hits        48338    48297      -41     
+ Misses       4470     4450      -20
Flag Coverage Δ
#multiple 90.12% <92.18%> (+0.02%) ⬆️
#single 41.8% <41.79%> (-0.03%) ⬇️
Impacted Files Coverage Δ
pandas/io/parquet.py 84.46% <ø> (-0.15%) ⬇️
pandas/compat/pickle_compat.py 75.3% <ø> (-0.31%) ⬇️
pandas/io/formats/latex.py 100% <ø> (ø) ⬆️
pandas/core/computation/scope.py 93.06% <ø> (ø) ⬆️
pandas/plotting/_timeseries.py 65.28% <0%> (-0.18%) ⬇️
pandas/core/panel.py 35.53% <0%> (ø) ⬆️
pandas/core/computation/engines.py 88.52% <0%> (-0.19%) ⬇️
pandas/io/json/normalize.py 96.93% <100%> (ø) ⬆️
pandas/plotting/_style.py 77.17% <100%> (-0.25%) ⬇️
pandas/util/testing.py 90.73% <100%> (+0.27%) ⬆️
... and 68 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 882961d...6701e71. Read the comment docs.

@codecov
Copy link

codecov bot commented Mar 28, 2019

Codecov Report

Merging #25903 into master will increase coverage by 0.01%.
The diff coverage is 94.86%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #25903      +/-   ##
==========================================
+ Coverage   91.77%   91.79%   +0.01%     
==========================================
  Files         175      175              
  Lines       52606    52538      -68     
==========================================
- Hits        48280    48228      -52     
+ Misses       4326     4310      -16
Flag Coverage Δ
#multiple 90.35% <93.28%> (+0.02%) ⬆️
#single 41.88% <41.89%> (-0.1%) ⬇️
Impacted Files Coverage Δ
pandas/io/parquet.py 84.46% <ø> (-0.15%) ⬇️
pandas/compat/pickle_compat.py 69.13% <ø> (-0.38%) ⬇️
pandas/io/formats/latex.py 100% <ø> (ø) ⬆️
pandas/core/computation/scope.py 93.06% <ø> (ø) ⬆️
pandas/plotting/_timeseries.py 65.28% <0%> (-0.18%) ⬇️
pandas/core/panel.py 35.53% <0%> (ø) ⬆️
pandas/core/computation/engines.py 88.52% <0%> (-0.19%) ⬇️
pandas/io/json/normalize.py 96.93% <100%> (ø) ⬆️
pandas/plotting/_style.py 77.17% <100%> (-0.25%) ⬇️
pandas/util/testing.py 90.63% <100%> (+0.17%) ⬆️
... and 68 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 7721f70...4137281. Read the comment docs.

Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

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

lgtm - over to you @jreback

@@ -1711,8 +1709,7 @@ def to_records(self, index=True, convert_datetime64=None,
# string naming a type.
if dtype_mapping is None:
formats.append(v.dtype)
elif isinstance(dtype_mapping, (type, np.dtype,
compat.string_types)):
elif isinstance(dtype_mapping, (type, np.dtype, str)):
Copy link
Member

Choose a reason for hiding this comment

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

Just thinking out loud but wondering if we should make something to fuse type, np.dtype and str. Would certainly help out in some of the typing things we have going on

@jreback
Copy link
Contributor

jreback commented Mar 28, 2019

can merge master. sorry i think merged something else and causes conflicts.

@jreback jreback merged commit 19626d2 into pandas-dev:master Mar 29, 2019
@jreback
Copy link
Contributor

jreback commented Mar 29, 2019

thanks @jschendel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Clean Strings String extension data type and string data
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants