Re: Can one output something other than 'nan' for not a number values?

2024-02-19 Thread dn via Python-list

On 20/02/24 01:04, Chris Green via Python-list wrote:

dn  wrote:

On 18/02/24 09:53, Grant Edwards via Python-list wrote:

On 2024-02-17, Cameron Simpson via Python-list  wrote:

On 16Feb2024 22:12, Chris Green  wrote:

I'm looking for a simple way to make NaN values output as something
like '-' or even just a space instead of the string 'nan'.
[...]

 Battery Voltages and Currents
 Leisure Battery - 12.42 volts  -0.52 Amps
 Starter Battery -   nan voltsnan Amps

What I would like is for those 'nan' strings to be just a '-' or
something similar.



The simplest thing is probably just a function writing it how you want
it:

   def float_s(f):
   if isnan(f):
   return "-"
   return str(f)

and then use eg:

   print(f'value is {float_s(value)}')

or whatever fits your code.


Except he's obviously using some sort of formatting to control the
number of columns and decimal places, so 'str(f)' is not going to cut
it. Is the basic floating point number formatting functionality seen
when using f-strings or '%' operator part of the float type or is it
part of the f-string and % operator?


It's part of the PSL's string library: "Format Specification
Mini-Language"
https://docs.python.org/3/library/string.html#format-specification-mini-language

Has the OP stated if we're talking 'Python' or numpy, pandas, ...?


Just python, on a Raspberry Pi, so currently Python 3.9.2.


Concur with earlier advice (and assuming is only a consideration during 
output) - use if.


Alternately, encode appropriately during the data-capture phase.


--
Regards,
=dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Can one output something other than 'nan' for not a number values?

2024-02-19 Thread dn via Python-list

On 20/02/24 05:58, Grant Edwards via Python-list wrote:

Here's a demonstration of how to hook custom code into the f-string
formatting engine. It's brilliantly depraved.

https://stackoverflow.com/questions/55876683/hook-into-the-builtin-python-f-string-format-machinery

 From the above:

 You can, but only if you write evil code that probably should
 never end up in production software. So let's get started!
 
 I'm not going to integrate it into your library, but I will show

 you how to hook into the behavior of f-strings. This is roughly
 how it'll work:
 
  1. Write a function that manipulates the bytecode instructions of

 code objects to replace FORMAT_VALUE instructions with calls
 to a hook function;
 
  2. Customize the import mechanism to make sure that the bytecode

 of every module and package (except standard library modules
 and site-packages) is modified with that function.

Final code is here:

https://github.com/mivdnber/formathack


Some of this (Expression components inside f-strings) newly available in 
v3.12 (PEP-701) - which can be used in production...


--
Regards,
=dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Testing (sorry)

2024-02-19 Thread Thomas Passin via Python-list

On 2/19/2024 11:55 AM, Skip Montanaro wrote:

Here is a typical bounce message that I get:

mailto:python-list@python.org>>: host
mail.python.org [188.166.95.178] said:
450-4.3.2
      Service currently unavailable 450 4.3.2

Some time after I get one of these messages I re-send the post. 
Usually

it gets through then.


Looks kinda like greylisting to me. I'm pretty sure that's one of the 
tool in the mail.python.org  chain.


I don't see it as greylisting.  A repeat post will succeed, before there 
would be time for my email provider (Dreamhost) to do anything about it.


--
https://mail.python.org/mailman/listinfo/python-list


Matplotlib warning [error?] message

2024-02-19 Thread Leif Svalgaard via Python-list
now I get:
 File e:\getmodpot.py:40
fig,ax = initPlot()

  File E:\mystuff.py:272 in initPlot
fig,ax = plt.subplots(figsize=(xs,ys))

  File ~\anaconda3\Lib\site-packages\matplotlib\pyplot.py:1501 in subplots
fig = figure(**fig_kw)

  File ~\anaconda3\Lib\site-packages\matplotlib\_api\deprecation.py:454 in
wrapper
return func(*args, **kwargs)

  File ~\anaconda3\Lib\site-packages\matplotlib\pyplot.py:840 in figure
manager = new_figure_manager(

  File ~\anaconda3\Lib\site-packages\matplotlib\pyplot.py:384 in
new_figure_manager
return _get_backend_mod().new_figure_manager(*args, **kwargs)

  File ~\anaconda3\Lib\site-packages\matplotlib\backend_bases.py:3573 in
new_figure_manager

  File ~\anaconda3\Lib\site-packages\matplotlib\_api\deprecation.py:454 in
wrapper
return func(*args, **kwargs)

  File ~\anaconda3\Lib\site-packages\matplotlib\figure.py:2505 in __init__
"The Figure parameters 'layout' and 'constrained_layout' "

  File ~\anaconda3\Lib\site-packages\matplotlib\figure.py:213 in __init__
self.set(**kwargs)

  File ~\anaconda3\Lib\site-packages\matplotlib\artist.py:147 in 
cls.set = lambda self, **kwargs: Artist.set(self, **kwargs)

  File ~\anaconda3\Lib\site-packages\matplotlib\artist.py:1227 in set
return self._internal_update(cbook.normalize_kwargs(kwargs, self))

  File ~\anaconda3\Lib\site-packages\matplotlib\cbook\__init__.py:1771 in
normalize_kwargs
for canonical, alias_list in alias_mapping.items()

AttributeError: 'Figure' object has no attribute 'items'

-- 
Leif Svalgaard
l...@leif.org
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Can one output something other than 'nan' for not a number values?

2024-02-19 Thread Grant Edwards via Python-list
On 2024-02-19, Chris Green via Python-list  wrote:

> It's using f'{...}' at the moment.

Here's a demonstration of how to hook custom code into the f-string
formatting engine. It's brilliantly depraved.

https://stackoverflow.com/questions/55876683/hook-into-the-builtin-python-f-string-format-machinery

>From the above:

You can, but only if you write evil code that probably should
never end up in production software. So let's get started!

I'm not going to integrate it into your library, but I will show
you how to hook into the behavior of f-strings. This is roughly
how it'll work:

 1. Write a function that manipulates the bytecode instructions of
code objects to replace FORMAT_VALUE instructions with calls
to a hook function;

 2. Customize the import mechanism to make sure that the bytecode
of every module and package (except standard library modules
and site-packages) is modified with that function.

Final code is here:

https://github.com/mivdnber/formathack

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Testing (sorry)

2024-02-19 Thread Skip Montanaro via Python-list
>
> Here is a typical bounce message that I get:
>
> : host mail.python.org[188.166.95.178] said:
> 450-4.3.2
>  Service currently unavailable 450 4.3.2
>
> Some time after I get one of these messages I re-send the post.  Usually
> it gets through then.
>

Looks kinda like greylisting to me. I'm pretty sure that's one of the tool
in the mail.python.org chain.

Skip

>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Testing (sorry)

2024-02-19 Thread Thomas Passin via Python-list

On 2/19/2024 9:17 AM, Grant Edwards via Python-list wrote:

On 2024-02-19, Thomas Passin  wrote:


About 24 hours later, all of my posts (and the confirmation e-mails)
all showed up in a burst at the same time on two different unrelated
e-mail accounts.

I still have no clue what was going on...


Sometimes a post of mine will not show up for hours or even half a day.
They are all addressed directly to the list.  Sometimes my email
provider sends me a notice that the message bounced.  Those notices say
that the address wasn't available when the transmission was tried.


Here is a typical bounce message that I get:

: host mail.python.org[188.166.95.178] said: 
450-4.3.2

Service currently unavailable 450 4.3.2

Some time after I get one of these messages I re-send the post.  Usually 
it gets through then.



I guess that in future I'll wait a couple days before I assume
something is broken.

--
Grant



--
https://mail.python.org/mailman/listinfo/python-list


Re: Testing (sorry)

2024-02-19 Thread Grant Edwards via Python-list
On 2024-02-19, Thomas Passin  wrote:

>> About 24 hours later, all of my posts (and the confirmation e-mails)
>> all showed up in a burst at the same time on two different unrelated
>> e-mail accounts.
>> 
>> I still have no clue what was going on...
>
> Sometimes a post of mine will not show up for hours or even half a day. 
> They are all addressed directly to the list.  Sometimes my email 
> provider sends me a notice that the message bounced.  Those notices say 
> that the address wasn't available when the transmission was tried.

I guess that in future I'll wait a couple days before I assume
something is broken.

--
Grant

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Can one output something other than 'nan' for not a number values?

2024-02-19 Thread Chris Green via Python-list
Grant Edwards  wrote:
> On 2024-02-16, Chris Green via Python-list  wrote:
> 
> > I'm looking for a simple way to make NaN values output as something
> > like '-' or even just a space instead of the string 'nan'.
> 
> It would probably help if you told us how you're "outputting" them now
> (the Python feaatures/functions used, not the actual output format).
> 
> Are you using f-strings, the % operator, str.format(), or ??
> 
> I would be tempted to try monkey-patching the float class to override
> the __format__ method. I have no idea what side effects that might
> have, or if it's even used by the various formatting mechanisms, so
> you might end up scraping bits off the walls...
> 
It's using f'{...}' at the moment.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Can one output something other than 'nan' for not a number values?

2024-02-19 Thread Chris Green via Python-list
dn  wrote:
> On 18/02/24 09:53, Grant Edwards via Python-list wrote:
> > On 2024-02-17, Cameron Simpson via Python-list  
> > wrote:
> >> On 16Feb2024 22:12, Chris Green  wrote:
> >>> I'm looking for a simple way to make NaN values output as something
> >>> like '-' or even just a space instead of the string 'nan'.
> >>> [...]
> >>>
> >>> Battery Voltages and Currents
> >>> Leisure Battery - 12.42 volts  -0.52 Amps
> >>> Starter Battery -   nan voltsnan Amps
> >>>
> >>> What I would like is for those 'nan' strings to be just a '-' or
> >>> something similar.
> > 
> >> The simplest thing is probably just a function writing it how you want
> >> it:
> >>
> >>   def float_s(f):
> >>   if isnan(f):
> >>   return "-"
> >>   return str(f)
> >>
> >> and then use eg:
> >>
> >>   print(f'value is {float_s(value)}')
> >>
> >> or whatever fits your code.
> > 
> > Except he's obviously using some sort of formatting to control the
> > number of columns and decimal places, so 'str(f)' is not going to cut
> > it. Is the basic floating point number formatting functionality seen
> > when using f-strings or '%' operator part of the float type or is it
> > part of the f-string and % operator?
> 
> It's part of the PSL's string library: "Format Specification 
> Mini-Language" 
> https://docs.python.org/3/library/string.html#format-specification-mini-language
> 
> Has the OP stated if we're talking 'Python' or numpy, pandas, ...?
> 
Just python, on a Raspberry Pi, so currently Python 3.9.2.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Testing (sorry)

2024-02-19 Thread Byunghee HWANG via Python-list
Hellow Grant,

On Sat, 2024-02-17 at 18:54 -0600, Grant Edwards via Python-list wrote:
> 
> Today I noticed that nothing I've posted to python-list in past 3
> weeks has shown up on the list. I don't know how to troubleshoot this
> other than sending test messages.  Obviously, if this shows up on the
> list, then I'm making progress.
> 
> [message 4]
> -- 
> Grant

Do not worry. Sending email is harder than coding in Python. Anyway,
your email arrived safely in my mailbox. Congratulations!


Thanks, Byunghee from South Korea



signature.asc
Description: This is a digitally signed message part
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Matplotlib warning [error?] message

2024-02-19 Thread Zahraa Fadhil via Python-list
On Sunday, February 18, 2024 at 10:48:29 PM UTC+3, Leif Svalgaard wrote:
> The latest[?] version of Matplotlib cannot show a figure. I get the 
> annoying error message: "Matplotlib is currently using agg, which is a 
> non-GUI backend, so cannot show the figure" 
> I'm using Spyder python 3.11 on Windows 11. 
> What to do? 
> 
> -- 
> Leif Svalgaard 
> 
I have the same problem
try this
1) add this line first 
%matplotlib inline
import matplotlib
import matplotlib.pyplot as plt

2) delete this line from your cod.matplotlib.use('Agg')

3) save the result into png file 
plt.savefig('D:\data\mygraph.png')


another solution 
https://www.w3schools.com/python/trypandas.asp?filename=demo_ml_dtree4

import sys
import matplotlib
matplotlib.use('Agg')

import matplotlib.pyplot as plt

#Two  lines to make compiler able to draw:
plt.savefig(sys.stdout.buffer)
sys.stdout.flush()

-- 
https://mail.python.org/mailman/listinfo/python-list